cancelable-promise
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -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); |
{ | ||
"name": "cancelable-promise", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"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
31916
387
7