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

cancelable-promise

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cancelable-promise - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

12

CancelablePromise.js

@@ -0,1 +1,9 @@

const handleCallback = (resolve, reject, callback, r) => {
try {
resolve(callback(r));
} catch (e) {
reject(e);
}
};
export default class CancelablePromise {

@@ -38,3 +46,3 @@ static all(iterable) {

if (success && !this._canceled) {
resolve(success(r));
handleCallback(resolve, reject, success, r);
} else {

@@ -48,3 +56,3 @@ resolve(r);

if (error && !this._canceled) {
resolve(error(r));
handleCallback(resolve, reject, error, r);
} else {

@@ -51,0 +59,0 @@ reject(r);

@@ -224,2 +224,38 @@ import {

});
it('should reject the promise when the success callback throws an error', (done) => {
const promise = new CancelablePromise((resolve, reject) => {
resolve('test123');
});
let hasFailed = true;
promise.then((value) => {
throw new Error('The callback threw an error');
}).catch((error) => {
hasFailed = false;
});
const end = () => {
done(hasFailed ? new Error('Promise should be rejected when the success callback throws an error') : undefined);
};
setTimeout(end, 0);
});
it('should reject the promise when the error callback throws an error', (done) => {
const promise = new CancelablePromise((resolve, reject) => {
reject(new Error('test123'));
});
let hasFailed = true;
promise.catch((error) => {
throw new Error('The callback threw an error');
}).catch((error) => {
hasFailed = false;
});
const end = () => {
done(hasFailed ? new Error('Promise should be rejected when the error callback throws an error') : undefined);
};
setTimeout(end, 0);
});
});

@@ -11,2 +11,10 @@ "use strict";

var handleCallback = function handleCallback(resolve, reject, callback, r) {
try {
resolve(callback(r));
} catch (e) {
reject(e);
}
};
var CancelablePromise = function () {

@@ -61,3 +69,3 @@ _createClass(CancelablePromise, null, [{

if (success && !_this._canceled) {
resolve(success(r));
handleCallback(resolve, reject, success, r);
} else {

@@ -71,3 +79,3 @@ resolve(r);

if (error && !_this._canceled) {
resolve(error(r));
handleCallback(resolve, reject, error, r);
} else {

@@ -74,0 +82,0 @@ reject(r);

2

package.json
{
"name": "cancelable-promise",
"version": "2.3.0",
"version": "2.4.0",
"description": "A simple cancelable promise",

@@ -5,0 +5,0 @@ "main": "dist/CancelablePromise.js",

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