- From: Robert Kieffer <notifications@github.com>
- Date: Tue, 18 May 2021 07:06:48 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/981@github.com>
The AbortController/Signal pattern is a bit cumbersome to use because it requires referencing the `signal` and `abort` and abort properties through the controller instance, which has no real utility other than as a container for these two properties. If `abort()` was bound to the contoller instance, developers could easily destructure the object rather than having to maintain an navigate through a 'controller' reference. For example, take this use case where an abortable action is being peformed, while delegating the `abort` function to an external control... ```javascript // Abort controller for this action ... const abortController = new AbortController(); // Delegate the abort function to external control (e.g. clickable button) $('#someButton').addEventListener('click', () => abortController.abort()); // abortable actions await someAction(abortController.signal); await otherAction(abortController.signal); // etc... ``` Making the suggested change would allow for this code, instead... ```javascript const {signal, abort} = new AbortController(); // ... abortable by some external event $('#someButton').addEventListener('click', abort); // ... now do actions, checking abort status await someAction(signal); await someAction(signal); ``` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/981
Received on Tuesday, 18 May 2021 14:07:11 UTC