Releases: alkemics/CancelablePromise
Releases · alkemics/CancelablePromise
4.3.1
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
4.2.1
4.2.0
4.1.0
- 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
- 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
3.2.0
- 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();