p-cancelable creates a cancelable promise, letting you register on-cancel handlers and call .cancel(reason) to synchronously reject the promise with a CancelError. It is useful for tasks like animations, loading resources, long-running async computations, and async iteration, and it is in maintenance state with no new features planned. For newer Node.js targets, the documentation recommends using AbortController instead.
Project status
- The source has a very recent update, on 2026-11-02, so it is active now, though the preceding update was in July 2022.
- Updates appear irregular rather than on a steady cadence, with a multi-year gap before the latest one.
AI summary generated
Recent updates
v5.0.0
Version 5.0.0 requires Node.js 22 or later and fixes several cancellation and promise-settlement issues. It also corrects the TypeScript declarations so PCancelable instances are Promise-compatible without claiming unavailable static Promise methods.
Breakingv4.0.1
v4.0.1 is a small bugfix release for p-cancelable that changes how the internal promise state is transitioned. Instead of unconditionally overwriting state on resolve/reject, the implementation now only updates the state when the promise is still pending, preventing late settle handlers from clobbering a canceled state.
v4.0.0
v4.0.0 bumps the minimum supported Node.js version to the 14.x line and modernizes the CI/test matrix. It also improves the error message thrown when attempting to attach an onCancel handler after the promise has already moved past the initial pending phase.
Breakingv3.0.0
Release v3.0.0 makes the package pure ESM and raises the minimum supported Node.js version to 12.20. The release notes call out these as breaking changes, and the code diff confirms an ESM transition plus related TypeScript definition and export changes.
Breakingv2.1.1
Release v2.1.1 is a minor update focused on TypeScript typings for p-cancelable. The release notes state it fixes the TypeScript type for the cancel method, and the diff shows only type declaration changes in index.d.ts plus the package version bump.
v2.1.0
Release v2.1.0 changes the cancellation behavior of `p-cancelable` so that registered `onCancel` handlers are executed immediately when `.cancel()` is called. The implementation also alters promise resolution behavior during cancellation, particularly when `onCancel.shouldReject` is enabled, and adds a small control-flow change around errors thrown inside cancel handlers.
v2.0.0
v2.0.0 makes p-cancelable stricter by requiring Node.js >= 8 and introducing a runtime guard that throws when an `onCancel` handler is added after a promise settles. It also changes the TypeScript declaration/export style to be CommonJS compatible. The runtime and type export surface show additional changes beyond what the release notes explicitly call out.
Breakingv1.1.0
This release adds TypeScript type definitions to the package, improving developer experience for TypeScript users. No other functional, behavioral, or compatibility changes are mentioned in the release notes.
Features