Platform and versions
Where easy-cancelable-promise runs, what the package ships, and what changes when you upgrade from version 2.
Where it runs
The library is plain JavaScript on top of the native Promise. It has no dependencies and does not depend on
any framework.
| Environment | Needs |
|---|---|
| Browsers | ES2020: Chrome 80, Edge 80, Firefox 74, Safari 13.1 |
| Node.js | 15 or later, for the global AbortController |
| Server rendering | Yes |
CancelableAbortController extends the global AbortController. Everything else only needs Promise.
What the package ships
- ES modules (
.mjs), CommonJS (.cjs) and TypeScript declarations for every entry. - One entry per module, besides the main one. See TypeScript.
"sideEffects": false, so bundlers drop what you do not import.- No dependencies.
Bundlers and Node with import load the ES modules. require loads the CommonJS files.
Upgrading from version 2
The public API is the same. What changed is how the package is built, and a number of cases that did not behave as documented.
| Change | What to do |
|---|---|
| Published files are ES modules and CommonJS | Nothing with a bundler. The UMD global for <script> tags is gone |
In Node, import X from 'easy-cancelable-promise' is the class | Before it was the object with all the exports. Use named imports |
| Every entry shares one class | instanceof now works between entries. Nothing to do |
resolve(promise) keeps the status pending | The status follows the promise you passed, and it can still be canceled |
| A callback that throws rejects the promise | Before, the constructor threw. Move the try / catch to the promise |
allSettled results are CancelablePromiseSettledResult | A variable typed PromiseSettledResult needs the new type |
groupAsCancelablePromise keeps the order of the tasks | Results were in completion order. Stop sorting them |
executeInOrder runs one task at a time | Before, the tasks of a batch started together |
Promises chained from a canceled promise are canceled | Their status was rejected. They still reject, so keep their catch |
Release notes
cancel()now reaches aCancelablePromiseused as the result of another promise.- A promise resolved with a pending promise stays pending, so it can be canceled; in 2.x that cancel was ignored.
New in version 3
beforeEachCallbackandafterEachCallbackreceive the position of their task.CancelablePromiseSettledResult, the type of the results ofallSettled.
Fixed in version 3
- A group with a task that is rejected now rejects. Before, it never settled.
- Canceling a group no longer leaves unhandled rejections.
beforeEachCallbackruns before its task starts.maxConcurrentbelow1behaves as1. Before, the group never finished.CancelablePromise.all([])andallSettled([])resolve with an empty array.allandallSettledkeep one result per value when the same promise is passed twice.resolveandrejectafter the promise settled are ignored, and the status no longer changes.- A cancel listener that throws no longer leaves the promise pending.
isCancelablePromiserecognizes promises created by another copy of the package.- An error thrown by an
asynccallback rejects the promise. Before, the promise stayed pending. toCancelablePromiseinfers the type of its result. Before,thenreceived a value typed as a promise.- The results of
allSettledinclude the status'canceled'in their type,CancelablePromiseSettledResult.
Related
- easy-web-worker: Web Workers whose calls return a
CancelablePromise. - The package on npm and the source on GitHub.