Back to Explore

sindresorhus/p-cancelable

GitHub
1 watchersOpen source

Last release:

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

  • Maintenance status: Appears quiet / in maintenance mode, based on the last listed updates being in 2022 (v4.0.1 on 2022-07-19). An upstream GitHub push exists on 2025-09-09, but no corresponding 2025 to 2026 p-cancelable update details are shown here.
  • Update cadence: Infrequent, with no evidence of regular releases after mid-2022. The gap from the last listed update to today (2026-08-12) is multiple years.

AI summary generated

AI-generated from public sources. May be inaccurate. Report

Recent updates

  • v4.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.

    Breaking
  • v3.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.

    Breaking
  • v2.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.

    Breaking
  • v1.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