Skip to content

Releases: alkemics/CancelablePromise

4.3.1

14 Oct 14:15
Compare
Choose a tag to compare

Noticeable changes:

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

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

Full Changelog: v4.3.0...v4.3.1

4.3.0

17 Mar 15:49
3865d14
Compare
Choose a tag to compare
  • 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

4.2.1

09 Jul 13:34
525f18b
Compare
Choose a tag to compare
  • add browser entrypoint in package.json
  • upgrade dev dependencies

4.2.0

09 Jul 13:33
c3a5083
Compare
Choose a tag to compare
  • Fix finally usecase always been called
  • Merge onCancelList and finallyList
  • Add isCancelablePromise util
  • Migrate to Typescript and improve umd/esm outputs

4.1.0

16 Jun 08:04
403db3f
Compare
Choose a tag to compare
  • 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

4.0.0

27 May 12:48
662cb76
Compare
Choose a tag to compare
  • 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.mjs

[Feature] ESM module

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

3.2.3

13 Jan 11:34
0204876
Compare
Choose a tag to compare
  • add types in package.json

3.2.0

10 Oct 11:08
2255de6
Compare
Choose a tag to compare
  • 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();

3.1.3

31 Aug 09:32
d660845
Compare
Choose a tag to compare
  • upgrade dev dependencies
  • add node v14 to nodejs workflows

3.1.1

30 Apr 23:25
57a34c1
Compare
Choose a tag to compare
  • export CancelablePromiseType and CancelablePromiseConstructor types
  • upgrade dev dependencies