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

cancel-token

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cancel-token

Implementation of https://github.com/littledan/proposal-cancelable-promises

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.4K
decreased by-43.21%
Maintainers
1
Weekly downloads
 
Created
Source

CancelToken and Cancel Polyfill

This a polyfill of the polyfillable parts of the proposed cancellable promises spec.

See https://github.com/littledan/proposal-cancelable-promises for more details.

Use

import {CancelToken} from 'cancel-token';

const source = CancelToken.source();

const result = someCancellableApi(source.token);

eventSource.on('dont-care-about-result-anymore', () {
  source.cancel();
});

// This may throw a Cancel if we called source.cancel().
const value = await result;


// Elsewhere, maybe in another library
async function someCancellableApi(cancelToken) {
  await doSomeWork(cancelToken);

  // I'm outside of a critical section here, so it's ok if I were to throw.
  cancelToken.throwIfRequested();

  return doSomeMoreWork(cancelToken);
}

Developing

To test:

npm test

To watch source files and rerun tests when they change:

npm test:watch

Keywords

FAQs

Package last updated on 16 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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