This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This a basic implementation of task cancellation using a Promise extension | |
combined with an AbortController. There are 3 major benefits to this implementation: | |
1. Because it's just an extension of a Promise the Task is fully | |
compatible with the async/await syntax. | |
2. By using the abort controller as a native cancellation token | |
fetch requests and certain DOM operations can be cancelled inside the task. | |
3. By passing the controller from parent tasks to new child tasks an entire | |
async chain can be cancelled using a single AbortController. |