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

p-cancelable

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-cancelable

Create a promise that can be canceled

  • 4.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20M
increased by2.65%
Maintainers
1
Weekly downloads
 
Created

What is p-cancelable?

The p-cancelable package provides a way to create cancelable promises in JavaScript. This is particularly useful for managing asynchronous operations that may need to be canceled before they complete, such as HTTP requests, long-running computations, or any other task that might not need to continue executing if certain conditions are met.

What are p-cancelable's main functionalities?

Creating a cancelable promise

This feature allows the creation of a new cancelable promise. The promise can be canceled at any time before it resolves or rejects, which triggers the onCancel function where cleanup operations like clearing timeouts or aborting requests can be performed.

const PCancelable = require('p-cancelable');

const myCancelablePromise = new PCancelable((resolve, reject, onCancel) => {
  const timer = setTimeout(() => {
    resolve('Done!');
  }, 2000);

  onCancel(() => {
    clearTimeout(timer);
    reject(new Error('Operation canceled.'));
  });
});

myCancelablePromise.cancel();

Other packages similar to p-cancelable

Keywords

FAQs

Package last updated on 19 Jul 2022

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