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

@nextgis/cancelable-promise

Package Overview
Dependencies
Maintainers
3
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nextgis/cancelable-promise

A promise you can stop

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
147
decreased by-83.39%
Maintainers
3
Weekly downloads
 
Created
Source

CancelablePromise

size version

A promise you can stop.

Installation

In Browser

Include assets

Simply download and include with a script tag, CancelablePromise will be registered as a global variable.

<script src="../lib/cancelable-promise.global.js"></script>

<script>
  var promise = new CancelablePromise((resolve, reject, onCancel) => {
    setTimeout(resolve, 1000);
    onCancel(() => console.log('canceled'));
  });
  promise.cancel();
</script>
CDN

unpkg

<script src="https://unpkg.com/@nextgis/cancelable-promise"></script>

jsdelivr

<script src="https://cdn.jsdelivr.net/npm/@nextgis/cancelable-promise"></script>

We recommend linking to a specific version number /cancelable-promise@[version]

In Node.js

npm install @nextgis/cancelable-promise

Usage

Catch CancelError

import CancelablePromise from "@nextgis/cancelable-promise";

const promise = new CancelablePromise((resolve, reject) => {
  setTimeout(() => resolve(), 100);
}).catch((er) => {
  if (er.name === "CancelError") {
    // handle cancel error
  }
  throw er;
});

promise.cancel();

Handle onCancel callback

import CancelablePromise from "@nextgis/cancelable-promise";

const promise = new CancelablePromise((resolve, reject, onCancel) => {
  const xhr = new XMLHttpRequest();
  xhr.open("GET", url, true);
  xhr.onload = () => {
    resolve(xhr.responseText);
  };
  xhr.onerror = (er) => {
    reject(er);
  };

  onCancel(() => {
    xhr.abort();
  });

  xhr.send();
});

promise.cancel();

Check out the API Documentation

Commercial support

Need to fix a bug or add a feature to @nextgis/cancelable-promise? We provide custom development and support for this software. Contact us to discuss options!

http://nextgis.com

Keywords

FAQs

Package last updated on 03 Apr 2024

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