cancelable-promise
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -68,6 +68,9 @@ const handleCallback = (resolve, reject, callback, r) => { | ||
cancel() { | ||
cancel(errorCallback) { | ||
this._canceled = true; | ||
if (errorCallback) { | ||
this._promise.catch(errorCallback); | ||
} | ||
return this; | ||
} | ||
} |
@@ -260,2 +260,29 @@ import { | ||
}); | ||
it('should call cancel function if rejected after a cancel', (done) => { | ||
const promise = new CancelablePromise((resolve, reject) => { | ||
reject(new Error('test456')); | ||
}); | ||
let cancelCalled = false; | ||
let catchCalled = false; | ||
promise.cancel((err) => { | ||
cancelCalled = true; | ||
}); | ||
promise.catch((err) => { | ||
catchCalled = true; | ||
}) | ||
const end = () => { | ||
let hasFailed = false; | ||
if (catchCalled) { | ||
hasFailed = 'Promise should NOT call catch when rejected after a cancel'; | ||
} else if (!cancelCalled) { | ||
hasFailed = 'Promise should call cancel error callback on a rejection'; | ||
} | ||
done(!!hasFailed ? new Error(hasFailed) : undefined); | ||
}; | ||
setTimeout(end, 0); | ||
}) | ||
}); |
@@ -92,4 +92,7 @@ "use strict"; | ||
key: "cancel", | ||
value: function cancel() { | ||
value: function cancel(errorCallback) { | ||
this._canceled = true; | ||
if (errorCallback) { | ||
this._promise.catch(errorCallback); | ||
} | ||
return this; | ||
@@ -96,0 +99,0 @@ } |
{ | ||
"name": "cancelable-promise", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "A simple cancelable promise", | ||
@@ -5,0 +5,0 @@ "main": "dist/CancelablePromise.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107968
9
416