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

cancelable-awaiter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cancelable-awaiter

A replacement for Typescript's default awaiter helper that supports Bluebird promise cancellations.

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by7.05%
Maintainers
1
Weekly downloads
 
Created
Source

Cancelable Awaiter

A replacement for Typescript's default awaiter helper that supports Bluebird promise cancellations.

Installation

npm install --save cancelable-awaiter

Usage

Depends on bluebird being installed as a dependency and configured to support cancellations:

import * as tslib from "tslib";
import * as Bluebird from "bluebird";
import * as awaiter from "cancelable-awaiter";

Bluebird.config({
    cancellation: true
});

(tslib as any).__awaiter = awaiter;

Note that in order for the above to work you also need to compile your project with the --importHelpers flag and install the tslib module.

Then async/await syntax can be used in conjunction with promise cancellations:

async function doSomeThings() {
    await doFirstThing()
        // will be invoked anyway:
        .finally(() => console.log("May have done first thing."));

    // may not execute this part if cancelled beforehand:
    console.log("Done first thing!");

    // may also be cancelled after first thing is done:
    await doSecondThing();
    console.log("Done second thing!");
}

const promise = doSomeThings()
    .finally(() => console.log("May have done some things."));

Promise.delay(1000)
    .then(() => promise.cancel());

Keywords

FAQs

Package last updated on 30 Jul 2019

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