Commit 08ff89d4 authored by Gabriel Monnerat's avatar Gabriel Monnerat Committed by Romain Courteaud

cancel: propagate message

parent e18484cb
...@@ -7,14 +7,14 @@ function promiseAtLeast(expected_count, promises) { ...@@ -7,14 +7,14 @@ function promiseAtLeast(expected_count, promises) {
throw new TypeError('You must pass an array to all.'); throw new TypeError('You must pass an array to all.');
} }
function canceller() { function canceller(msg) {
var promise; var promise;
for (var i = 0; i < promises.length; i++) { for (var i = 0; i < promises.length; i++) {
promise = promises[i]; promise = promises[i];
if (promise && typeof promise.then === 'function' && if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') { typeof promise.cancel === 'function') {
promise.cancel(); promise.cancel(msg);
} }
} }
} }
......
...@@ -12,7 +12,7 @@ function size(object) { ...@@ -12,7 +12,7 @@ function size(object) {
function hash(promises) { function hash(promises) {
function canceller() { function canceller(msg) {
var promise, var promise,
key; key;
for (key in promises) { for (key in promises) {
...@@ -21,7 +21,7 @@ function hash(promises) { ...@@ -21,7 +21,7 @@ function hash(promises) {
if (promise && typeof promise.then === 'function' && if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') { typeof promise.cancel === 'function') {
promise.cancel(); promise.cancel(msg);
} }
} }
} }
......
...@@ -45,21 +45,21 @@ var Promise = function(resolver, canceller) { ...@@ -45,21 +45,21 @@ var Promise = function(resolver, canceller) {
this.on('error', onerror); this.on('error', onerror);
this.cancel = function () { this.cancel = function (msg) {
// For now, simply reject the promise and does not propagate the cancel // For now, simply reject the promise and does not propagate the cancel
// to parent or children // to parent or children
if (resolved) { return; } if (resolved) { return; }
promise.isCancelled = true; promise.isCancelled = true;
if (canceller !== undefined) { if (canceller !== undefined) {
try { try {
canceller(); canceller(msg);
} catch (e) { } catch (e) {
rejectPromise(e); rejectPromise(e);
return; return;
} }
} }
// Trigger cancel? // Trigger cancel?
rejectPromise(new CancellationError()); rejectPromise(new CancellationError(msg));
}; };
try { try {
......
...@@ -24,9 +24,9 @@ var Queue = function(thenable) { ...@@ -24,9 +24,9 @@ var Queue = function(thenable) {
return new Queue(thenable); return new Queue(thenable);
} }
function canceller() { function canceller(msg) {
for (var i = promise_list.length; i > 0; i--) { for (var i = promise_list.length; i > 0; i--) {
promise_list[i - 1].cancel(); promise_list[i - 1].cancel(msg);
} }
} }
...@@ -69,10 +69,10 @@ var Queue = function(thenable) { ...@@ -69,10 +69,10 @@ var Queue = function(thenable) {
checkPromise(resolve(thenable)); checkPromise(resolve(thenable));
queue.cancel = function () { queue.cancel = function (msg) {
if (resolved) {return;} if (resolved) {return;}
resolved = true; resolved = true;
promise.cancel(); promise.cancel(msg);
promise.fail(function (rejectedReason) { promise.fail(function (rejectedReason) {
queue.isRejected = true; queue.isRejected = true;
queue.rejectedReason = rejectedReason; queue.rejectedReason = rejectedReason;
......
...@@ -9,9 +9,9 @@ function resolve(thenable) { ...@@ -9,9 +9,9 @@ function resolve(thenable) {
} }
} }
return resolve(thenable); return resolve(thenable);
}, function () { }, function (msg) {
if ((thenable !== undefined) && (thenable.cancel !== undefined)) { if ((thenable !== undefined) && (thenable.cancel !== undefined)) {
thenable.cancel(); thenable.cancel(msg);
} }
}); });
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment