-
Notifications
You must be signed in to change notification settings - Fork 54
Description
The design principles recommend using an AbortController for canceling asynchronous operations. This guidance has filtered down to other specifications such as w3c/web-nfc#225 and w3c/wake-lock#183. In the case of Wake Lock this resulted in something which was felt to be a very awkward design and during the Devices and Sensors F2F meeting at TPAC 2019 we resolved on w3c/wake-lock#214 to remove the AbortSignal in favor of the same ID pattern used by APIs such as setInterval()/clearInterval().
The decision within that group was that an AbortSignal is appropriate for a Promise-returning API which requires cancellation of an operation before the Promise is resolved. Non-Promise-returning APIs, or APIs which resolve the Promise after the operation has been initiated, should not take an AbortSignal.
As an example, the NFCReader interface's scan() method does not return a Promise and may generate multiple "reading" events or an "error" event. It should not take an AbortSignal and instead have a stopScan() or similar method. In contrast the NFCWriter interface's push() method performs a single write operation, after which the returned Promise is resolved. This method should take an AbortSignal.
We would like feedback from the TAG on this decision and clarification in the design principles.