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) {
throw new TypeError('You must pass an array to all.');
}
function canceller() {
function canceller(msg) {
var promise;
for (var i = 0; i < promises.length; i++) {
promise = promises[i];
if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') {
promise.cancel();
promise.cancel(msg);
}
}
}
......
......@@ -12,7 +12,7 @@ function size(object) {
function hash(promises) {
function canceller() {
function canceller(msg) {
var promise,
key;
for (key in promises) {
......@@ -21,7 +21,7 @@ function hash(promises) {
if (promise && typeof promise.then === 'function' &&
typeof promise.cancel === 'function') {
promise.cancel();
promise.cancel(msg);
}
}
}
......
......@@ -45,21 +45,21 @@ var Promise = function(resolver, canceller) {
this.on('error', onerror);
this.cancel = function () {
this.cancel = function (msg) {
// For now, simply reject the promise and does not propagate the cancel
// to parent or children
if (resolved) { return; }
promise.isCancelled = true;
if (canceller !== undefined) {
try {
canceller();
canceller(msg);
} catch (e) {
rejectPromise(e);
return;
}
}
// Trigger cancel?
rejectPromise(new CancellationError());
rejectPromise(new CancellationError(msg));
};
try {
......
......@@ -24,9 +24,9 @@ var Queue = function(thenable) {
return new Queue(thenable);
}
function canceller() {
function canceller(msg) {
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) {
checkPromise(resolve(thenable));
queue.cancel = function () {
queue.cancel = function (msg) {
if (resolved) {return;}
resolved = true;
promise.cancel();
promise.cancel(msg);
promise.fail(function (rejectedReason) {
queue.isRejected = true;
queue.rejectedReason = rejectedReason;
......
......@@ -9,9 +9,9 @@ function resolve(thenable) {
}
}
return resolve(thenable);
}, function () {
}, function (msg) {
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