Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cancelable-promise

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cancelable-promise - npm Package Versions

23

4.3.1

Diff

Changelog

Source

4.3.1 (2022-10-14)

Noticeable changes:

  • fix(type): add toStringTag symbol to class fields to be compatible with Promise type

Other changes:

  • chore(release): update preparation commit message
  • chore(deps-dev): bump @babel/preset-env from 7.19.3 to 7.19.4
  • chore(deps-dev): bump terser from 5.15.0 to 5.15.1
  • chore(deps-dev): bump core-js from 3.25.3 to 3.25.5
  • chore(deps-dev): bump @babel/cli from 7.18.10 to 7.19.3
  • chore(deps-dev): bump @babel/core from 7.19.1 to 7.19.3
  • chore(deps-dev): bump @babel/preset-typescript from 7.17.12 to 7.18.6
  • fix(cypress): migrate cypress config file for v10
  • fix(tests): fix tests for jest v28
alkemics
published 4.3.0 •

Changelog

Source

4.3.0 (2022-03-14)

  • chore(deps-dev): bump @typescript-eslint/eslint-plugin
  • chore(deps-dev): bump @typescript-eslint/parser from 5.13.0 to 5.14.0
  • chore(deps-dev): bump lint-staged from 12.3.4 to 12.3.5
  • feat(any): support Promise.any
alkemics
published 4.2.1 •

Changelog

Source

4.2.1 (2021-07-09)

  • add browser entrypoint in package.json
  • upgrade dev dependencies
alkemics
published 4.2.0 •

Changelog

Source

4.2.0 (2021-06-17)

  • Fix finally usecase always been called
  • Merge onCancelList and finallyList
  • Add isCancelablePromise util
  • Migrate to Typescript and improve umd/esm outputs
alkemics
published 4.1.0 •

Changelog

Source

4.1.0 (2021-06-16)

  • Prepare release without commit
  • Cancel cancelable promise returned by a then/catch callback

Consider this example:

const { CancelablePromise } = require('cancelable-promise');

const promise1 = new CancelablePromise((resolve, reject, onCancel) => {
  const timer = setTimeout(() => {
    console.log('resolve promise1');
    resolve();
  }, 1000);
  const abort = () => {
    clearTimeout(timer);
  };
  onCancel(abort);
});

const promise2 = promise1.then(() => {
  const promise3 = new CancelablePromise((resolve, reject, onCancel) => {
    const timer = setTimeout(() => {
      console.log('resolve promise 3');
      resolve();
    }, 1000);
    const abort = () => {
      clearTimeout(timer);
    };
    onCancel(abort);
  });
  return promise3;
});

setTimeout(() => {
  console.log('cancel promise 2');
  promise2.cancel();
}, 1500);

Before this release, output was:

resolve promise1
cancel promise 2
resolve promise 3

Now if you return a cancelable promise in a then/catch callback, it will cancel it too when you are canceling the parent promise. Output will be:

resolve promise1
cancel promise 2
alkemics
published 4.0.0 •

Changelog

Source

4.0.0 (2021-05-27)

  • Update dependencies and add esm module

[Breaking change]

No more dist folder, you will find releases in umd and esm folders.

- https://unpkg.com/cancelable-promise@3.0.0/dist/CancelablePromise.min.js
+ https://unpkg.com/cancelable-promise@4.0.0/umd/CancelablePromise.min.js
+ https://unpkg.com/cancelable-promise@4.0.0/esm/CancelablePromise.min.js

[Feature] ESM module

<script type="module">
  import { cancelable } from 'https://unpkg.com/cancelable-promise@4.0.0/esm/CancelablePromise.min.mjs';
</script>
alkemics
published 3.2.3 •

Changelog

Source

3.2.3 (2021-01-13)

  • add types in package.json
alkemics
published 3.2.2 •

alkemics
published 3.2.1 •

sdavid
published 3.2.0 •

Changelog

Source

3.2.0 (2020-10-10)

  • feature: execute onCancel or finally callback when promise is canceled
import CancelablePromise from 'cancelable-promise';

const promise = new CancelablePromise((resolve, reject, onCancel) => {
  const worker = new Worker('some-script.js');

  onCancel(() => {
    worker.terminate();
  });

  worker.onmessage = (event) => resolve(event.data);
  worker.onerror = (error) => reject(error);
});

promise.cancel(); // It will execute the callback passed to onCancel
let worker;
const promise = cancelable(
  new Promise((resolve, reject) => {
    worker = new Worker('some-script.js');
    worker.onmessage = (event) => {
      resolve(event.data); // never executed
    };
    worker.onerror = (error) => {
      reject(error); // never executed
    };
  })
)
  .then(() => {
    console.log('never logged');
  })
  .finally(
    () => {
      console.log('executed');
      if (worker) {
        worker.terminate();
        worker = null;
      }
    },
    // runWhenCanceled boolean
    true
  );

promise.cancel();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc