Cancellation tokens are composable entities that allow cancelling asynchronous operations.
The implementation roughly follows these TC39 proposals:
- https://github.com/tc39/proposal-cancellation
- https://github.com/tc39/proposal-cancelable-promises
The implementation is written in TypeScript and therefore comes with typings already bundled.
Install the library via your favourite package manager.
npm install cancellationtoken
or
yarn add cancellationtoken
You can create a new cancellation token along with a function to cancel it via create
. Functions can consume tokens by accessing the ìsCancelled
property.
import CancellationToken from 'cancellationtoken'
const { cancel, token } = CancellationToken.create()
console.log(token.isCancelled) // prints false
cancel()
console.log(token.isCancelled) // prints true
Coming soon! Meanwhile you can use the TypeScript definitions and examples.
git clone https://github.com/conradreuter/cancellationtoken
cd cancellationtoken/
yarn
yarn example 01-usage
conradreuter 💻 📖 💡 |
Andrew Arnott 💻 🐛 📖 |
---|