Socket
Socket
Sign inDemoInstall

@billogram/cancelable-promise

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@billogram/cancelable-promise

> A function for making a global promise "cancelable"


Version published
Weekly downloads
1
decreased by-90%
Maintainers
5
Weekly downloads
 
Created
Source

@billogram/cancelable-promise

A function for making a global promise "cancelable"

Install

yarn add @billogram/cancelable-promise

Usage

import {
    makeCancelablePromise,
} from '@billogram/cancelable-promise';

See types for exported types.

makeCancelablePromise

import {
    Data,
} from './types';


const promise = new Promise((resolve, reject) => {
    /* ... */
});

const [cancelablePromise, cancel] = makeCancelablePromise(promise);

try {
    const token: CancellationFulfillmentToken<Data> = await cancelablePromise;

    if (!token.isPromiseCanceled) {
        const data = token.value;

        // ...
    }
} catch (e) {
    const token = e as CancellationRejectionToken<unknown>;

    if (!token.isPromiseCanceled) {
        const reason = token.reason;

        // ...
    }
}

Note

This library is being published with our use cases in mind and is not necessarily meant to be consumed by the broader public. We probably won't take your feature requests unless they align with our own needs.

License

MIT

FAQs

Package last updated on 27 Jul 2021

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