cancelable-promise
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -26,6 +26,7 @@ export default class CancelablePromise { | ||
p.cancel(); | ||
resolve(); | ||
} | ||
if (success && !this._canceled) { | ||
resolve(success(r)); | ||
} else { | ||
resolve(r); | ||
} | ||
@@ -35,6 +36,7 @@ }, (r) => { | ||
p.cancel(); | ||
reject(); | ||
} | ||
if (error && !this._canceled) { | ||
reject(error(r)); | ||
resolve(error(r)); | ||
} else { | ||
resolve(r); | ||
} | ||
@@ -41,0 +43,0 @@ }); |
@@ -16,12 +16,14 @@ import { assert, expect } from 'chai'; | ||
const promise = new CancelablePromise((resolve, reject) => { | ||
reject('nop'); | ||
reject('eagle'); | ||
}); | ||
promise.then(() => { | ||
const promise2 = promise.then(() => { | ||
done(new Error('Success callback should not be executed')); | ||
}, (reason) => { | ||
expect(reason).to.be.equal('nop'); | ||
expect(reason).to.be.equal('eagle'); | ||
end(); | ||
return reason; | ||
}).catch((reason) => { | ||
expect(reason).to.be.equal('nop'); | ||
return 'rabbit'; | ||
}); | ||
promise2.then((reason) => { | ||
expect(reason).to.be.equal('rabbit'); | ||
end(); | ||
@@ -46,3 +48,3 @@ }); | ||
it('should works like a tree', (done) => { | ||
it('should work like a tree', (done) => { | ||
const end = createEnd(done, 2); | ||
@@ -72,3 +74,3 @@ const promise = new CancelablePromise((resolve, reject) => { | ||
it('should works also when then is added in a then', (done) => { | ||
it('should work also when then is added in a then', (done) => { | ||
const end = createEnd(done, 2); | ||
@@ -93,2 +95,21 @@ const promise = new CancelablePromise((resolve, reject) => { | ||
it('should work when empty or partial then', (done) => { | ||
const end = createEnd(done, 2); | ||
const promise = new CancelablePromise((resolve, reject) => { | ||
resolve('test123'); | ||
}); | ||
const promise2 = promise.then(); | ||
promise2.then((value) => { | ||
console.log(value); | ||
expect(value).to.be.equal('test123'); | ||
end(); | ||
return 'fox'; | ||
}).then((value) => { | ||
console.log(value); | ||
expect(value).to.be.equal('fox'); | ||
end(); | ||
}); | ||
}); | ||
it('should not execute callbacks if canceled', (done) => { | ||
@@ -95,0 +116,0 @@ let hasFailed = false; |
@@ -53,6 +53,7 @@ "use strict"; | ||
p.cancel(); | ||
resolve(); | ||
} | ||
if (success && !_this._canceled) { | ||
resolve(success(r)); | ||
} else { | ||
resolve(r); | ||
} | ||
@@ -62,6 +63,7 @@ }, function (r) { | ||
p.cancel(); | ||
reject(); | ||
} | ||
if (error && !_this._canceled) { | ||
reject(error(r)); | ||
resolve(error(r)); | ||
} else { | ||
resolve(r); | ||
} | ||
@@ -68,0 +70,0 @@ }); |
{ | ||
"name": "cancelable-promise", | ||
"version": "2.1.0", | ||
"version": "2.1.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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26908
259
0