Commit 27cc7f68 authored by Romain Courteaud's avatar Romain Courteaud

Publish build version of rsvp

parent 46330d04
...@@ -50,6 +50,7 @@ var Promise = function(resolver, canceller) { ...@@ -50,6 +50,7 @@ var Promise = function(resolver, canceller) {
// 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;
if (canceller !== undefined) { if (canceller !== undefined) {
try { try {
canceller(); canceller();
...@@ -81,6 +82,7 @@ var invokeCallback = function(type, promise, callback, event) { ...@@ -81,6 +82,7 @@ var invokeCallback = function(type, promise, callback, event) {
if (promise.isFulfilled) { return; } if (promise.isFulfilled) { return; }
if (promise.isRejected) { return; } if (promise.isRejected) { return; }
if (promise.isCancelled) { return; }
if (hasCallback) { if (hasCallback) {
try { try {
...@@ -111,6 +113,7 @@ var invokeCallback = function(type, promise, callback, event) { ...@@ -111,6 +113,7 @@ var invokeCallback = function(type, promise, callback, event) {
Promise.prototype = { Promise.prototype = {
constructor: Promise, constructor: Promise,
isCancelled: undefined,
isRejected: undefined, isRejected: undefined,
isFulfilled: undefined, isFulfilled: undefined,
rejectedReason: undefined, rejectedReason: undefined,
......
...@@ -13,7 +13,7 @@ function ResolvedQueueError(message) { ...@@ -13,7 +13,7 @@ function ResolvedQueueError(message) {
ResolvedQueueError.prototype = new Error(); ResolvedQueueError.prototype = new Error();
ResolvedQueueError.prototype.constructor = ResolvedQueueError; ResolvedQueueError.prototype.constructor = ResolvedQueueError;
var Queue = function() { var Queue = function(thenable) {
var queue = this, var queue = this,
promise_list = [], promise_list = [],
promise, promise,
...@@ -26,11 +26,31 @@ var Queue = function() { ...@@ -26,11 +26,31 @@ var Queue = function() {
} }
function canceller() { function canceller() {
for (var i = 0; i < 2; i++) { for (var i = promise_list.length; i > 0; i--) {
promise_list[i].cancel(); promise_list[i - 1].cancel();
} }
} }
function checkPromise(next_promise) {
promise_list.push(next_promise);
// Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
return fulfillmentValue;
}
}, function (rejectedReason) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
reject(rejectedReason);
} else {
throw rejectedReason;
}
}));
}
promise = new Promise(function(done, fail) { promise = new Promise(function(done, fail) {
fulfill = function (fulfillmentValue) { fulfill = function (fulfillmentValue) {
if (resolved) {return;} if (resolved) {return;}
...@@ -48,13 +68,7 @@ var Queue = function() { ...@@ -48,13 +68,7 @@ var Queue = function() {
}; };
}, canceller); }, canceller);
promise_list.push(resolve()); checkPromise(resolve(thenable));
promise_list.push(promise_list[0].then(function () {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill();
}
}));
queue.cancel = function () { queue.cancel = function () {
if (resolved) {return;} if (resolved) {return;}
...@@ -77,25 +91,9 @@ var Queue = function() { ...@@ -77,25 +91,9 @@ var Queue = function() {
throw new ResolvedQueueError(); throw new ResolvedQueueError();
} }
next_promise = last_promise.then(done, fail);
promise_list.push(next_promise);
// Handle pop // Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) { checkPromise(last_promise.then(done, fail));
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
return fulfillmentValue;
}
}, function (rejectedReason) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
reject(rejectedReason);
} else {
throw rejectedReason;
}
}));
return this; return this;
}; };
......
...@@ -519,6 +519,7 @@ define("rsvp/promise", ...@@ -519,6 +519,7 @@ define("rsvp/promise",
// 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;
if (canceller !== undefined) { if (canceller !== undefined) {
try { try {
canceller(); canceller();
...@@ -550,6 +551,7 @@ define("rsvp/promise", ...@@ -550,6 +551,7 @@ define("rsvp/promise",
if (promise.isFulfilled) { return; } if (promise.isFulfilled) { return; }
if (promise.isRejected) { return; } if (promise.isRejected) { return; }
if (promise.isCancelled) { return; }
if (hasCallback) { if (hasCallback) {
try { try {
...@@ -580,6 +582,7 @@ define("rsvp/promise", ...@@ -580,6 +582,7 @@ define("rsvp/promise",
Promise.prototype = { Promise.prototype = {
constructor: Promise, constructor: Promise,
isCancelled: undefined,
isRejected: undefined, isRejected: undefined,
isFulfilled: undefined, isFulfilled: undefined,
rejectedReason: undefined, rejectedReason: undefined,
...@@ -721,7 +724,7 @@ define("rsvp/queue", ...@@ -721,7 +724,7 @@ define("rsvp/queue",
ResolvedQueueError.prototype = new Error(); ResolvedQueueError.prototype = new Error();
ResolvedQueueError.prototype.constructor = ResolvedQueueError; ResolvedQueueError.prototype.constructor = ResolvedQueueError;
var Queue = function() { var Queue = function(thenable) {
var queue = this, var queue = this,
promise_list = [], promise_list = [],
promise, promise,
...@@ -734,11 +737,31 @@ define("rsvp/queue", ...@@ -734,11 +737,31 @@ define("rsvp/queue",
} }
function canceller() { function canceller() {
for (var i = 0; i < 2; i++) { for (var i = promise_list.length; i > 0; i--) {
promise_list[i].cancel(); promise_list[i - 1].cancel();
} }
} }
function checkPromise(next_promise) {
promise_list.push(next_promise);
// Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
return fulfillmentValue;
}
}, function (rejectedReason) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
reject(rejectedReason);
} else {
throw rejectedReason;
}
}));
}
promise = new Promise(function(done, fail) { promise = new Promise(function(done, fail) {
fulfill = function (fulfillmentValue) { fulfill = function (fulfillmentValue) {
if (resolved) {return;} if (resolved) {return;}
...@@ -756,13 +779,7 @@ define("rsvp/queue", ...@@ -756,13 +779,7 @@ define("rsvp/queue",
}; };
}, canceller); }, canceller);
promise_list.push(resolve()); checkPromise(resolve(thenable));
promise_list.push(promise_list[0].then(function () {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill();
}
}));
queue.cancel = function () { queue.cancel = function () {
if (resolved) {return;} if (resolved) {return;}
...@@ -785,25 +802,9 @@ define("rsvp/queue", ...@@ -785,25 +802,9 @@ define("rsvp/queue",
throw new ResolvedQueueError(); throw new ResolvedQueueError();
} }
next_promise = last_promise.then(done, fail);
promise_list.push(next_promise);
// Handle pop // Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) { checkPromise(last_promise.then(done, fail));
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
return fulfillmentValue;
}
}, function (rejectedReason) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
reject(rejectedReason);
} else {
throw rejectedReason;
}
}));
return this; return this;
}; };
......
...@@ -556,6 +556,7 @@ define("rsvp/promise", ...@@ -556,6 +556,7 @@ define("rsvp/promise",
// 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;
if (canceller !== undefined) { if (canceller !== undefined) {
try { try {
canceller(); canceller();
...@@ -587,6 +588,7 @@ define("rsvp/promise", ...@@ -587,6 +588,7 @@ define("rsvp/promise",
if (promise.isFulfilled) { return; } if (promise.isFulfilled) { return; }
if (promise.isRejected) { return; } if (promise.isRejected) { return; }
if (promise.isCancelled) { return; }
if (hasCallback) { if (hasCallback) {
try { try {
...@@ -617,6 +619,7 @@ define("rsvp/promise", ...@@ -617,6 +619,7 @@ define("rsvp/promise",
Promise.prototype = { Promise.prototype = {
constructor: Promise, constructor: Promise,
isCancelled: undefined,
isRejected: undefined, isRejected: undefined,
isFulfilled: undefined, isFulfilled: undefined,
rejectedReason: undefined, rejectedReason: undefined,
...@@ -758,7 +761,7 @@ define("rsvp/queue", ...@@ -758,7 +761,7 @@ define("rsvp/queue",
ResolvedQueueError.prototype = new Error(); ResolvedQueueError.prototype = new Error();
ResolvedQueueError.prototype.constructor = ResolvedQueueError; ResolvedQueueError.prototype.constructor = ResolvedQueueError;
var Queue = function() { var Queue = function(thenable) {
var queue = this, var queue = this,
promise_list = [], promise_list = [],
promise, promise,
...@@ -771,11 +774,31 @@ define("rsvp/queue", ...@@ -771,11 +774,31 @@ define("rsvp/queue",
} }
function canceller() { function canceller() {
for (var i = 0; i < 2; i++) { for (var i = promise_list.length; i > 0; i--) {
promise_list[i].cancel(); promise_list[i - 1].cancel();
} }
} }
function checkPromise(next_promise) {
promise_list.push(next_promise);
// Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
return fulfillmentValue;
}
}, function (rejectedReason) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
reject(rejectedReason);
} else {
throw rejectedReason;
}
}));
}
promise = new Promise(function(done, fail) { promise = new Promise(function(done, fail) {
fulfill = function (fulfillmentValue) { fulfill = function (fulfillmentValue) {
if (resolved) {return;} if (resolved) {return;}
...@@ -793,13 +816,7 @@ define("rsvp/queue", ...@@ -793,13 +816,7 @@ define("rsvp/queue",
}; };
}, canceller); }, canceller);
promise_list.push(resolve()); checkPromise(resolve(thenable));
promise_list.push(promise_list[0].then(function () {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill();
}
}));
queue.cancel = function () { queue.cancel = function () {
if (resolved) {return;} if (resolved) {return;}
...@@ -822,25 +839,9 @@ define("rsvp/queue", ...@@ -822,25 +839,9 @@ define("rsvp/queue",
throw new ResolvedQueueError(); throw new ResolvedQueueError();
} }
next_promise = last_promise.then(done, fail);
promise_list.push(next_promise);
// Handle pop // Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) { checkPromise(last_promise.then(done, fail));
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
} else {
return fulfillmentValue;
}
}, function (rejectedReason) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
reject(rejectedReason);
} else {
throw rejectedReason;
}
}));
return this; return this;
}; };
......
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