Skip to content
easy-cancelable-promise

Troubleshooting

Symptoms you may run into with cancelable promises, what causes each one, and how to fix it.

Problem solvingTypeScriptTry an example

Canceling does not stop the work

cancel tells everyone to stop waiting. The work stops only if the promise has an onCancel listener that stops it: clears the timer, aborts the request, closes the socket.

cancel does nothing

The promise was already resolved, rejected or canceled. A settled promise cannot be canceled: cancel returns the promise and calls no listener. Read promise.status to see how it ended.

An unhandled rejection after canceling

The promise you call cancel on never causes an unhandled rejection. A promise you created from it with then or finally is a different promise: it is canceled too, and it rejects with the same reason. Add a catch to the chain you created, or call cancel on the last promise of the chain instead.

instanceof CancelablePromise is false

Two copies of the class are loaded. This happens when one part of a Node application loads the package with import and another with require: Node treats the ES module and the CommonJS files as different modules.

Use isCancelablePromise(value) instead. It recognizes the promises of every copy.

Versions before 3 also had one copy per entry: a promise created through easy-cancelable-promise/defer was not an instance of the class exported by easy-cancelable-promise/CancelablePromise. That is fixed in version 3.

A progress listener is never called

Progress reports are not stored. A listener receives the reports sent after it was registered.

  • Register onProgress right after creating the promise.
  • Do not call reportProgress in the synchronous part of the callback: nobody can be listening yet.
  • After the promise settles its listeners are removed.

groupAsCancelablePromise returns null

The list of tasks is empty. Check the list before calling it, or handle null.

Cannot find name ‘AbortController’

The declarations of the package use AbortController and AbortSignal. Add "dom" to the lib option of your tsconfig.json, or install @types/node.

Documentation
↑↓ Navigate ↵ Open Esc Closeeasy-cancelable-promise docs
Get started

Promises you can actually control.