Commit 58953a31 authored by Tristan Cavelier's avatar Tristan Cavelier

Queue notifications are now enabled

parent 41eba17a
...@@ -18,6 +18,7 @@ var Queue = function() { ...@@ -18,6 +18,7 @@ var Queue = function() {
promise, promise,
fulfill, fulfill,
reject, reject,
notify,
resolved; resolved;
if (!(this instanceof Queue)) { if (!(this instanceof Queue)) {
...@@ -30,7 +31,7 @@ var Queue = function() { ...@@ -30,7 +31,7 @@ var Queue = function() {
} }
} }
promise = new Promise(function(done, fail) { promise = new Promise(function(done, fail, progress) {
fulfill = function (fulfillmentValue) { fulfill = function (fulfillmentValue) {
if (resolved) {return;} if (resolved) {return;}
queue.isFulfilled = true; queue.isFulfilled = true;
...@@ -45,6 +46,7 @@ var Queue = function() { ...@@ -45,6 +46,7 @@ var Queue = function() {
resolved = true; resolved = true;
return fail(rejectedReason); return fail(rejectedReason);
}; };
notify = progress;
}, canceller); }, canceller);
promise_list.push(delay()); promise_list.push(delay());
...@@ -68,7 +70,7 @@ var Queue = function() { ...@@ -68,7 +70,7 @@ var Queue = function() {
return promise.then.apply(promise, arguments); return promise.then.apply(promise, arguments);
}; };
queue.push = function(done, fail) { queue.push = function(done, fail, progress) {
var last_promise = promise_list[promise_list.length - 1], var last_promise = promise_list[promise_list.length - 1],
next_promise; next_promise;
...@@ -76,11 +78,11 @@ var Queue = function() { ...@@ -76,11 +78,11 @@ var Queue = function() {
throw new ResolvedQueueError(); throw new ResolvedQueueError();
} }
next_promise = last_promise.then(done, fail); next_promise = last_promise.then(done, fail, progress);
promise_list.push(next_promise); promise_list.push(next_promise);
// Handle pop // Handle pop
promise_list.push(next_promise.then(function (fulfillmentValue) { last_promise = next_promise.then(function (fulfillmentValue) {
promise_list.splice(0, 2); promise_list.splice(0, 2);
if (promise_list.length === 0) { if (promise_list.length === 0) {
fulfill(fulfillmentValue); fulfill(fulfillmentValue);
...@@ -94,7 +96,13 @@ var Queue = function() { ...@@ -94,7 +96,13 @@ var Queue = function() {
} else { } else {
throw rejectedReason; throw rejectedReason;
} }
})); }, function (notificationValue) {
if (promise_list[promise_list.length - 1] === last_promise) {
notify(notificationValue);
}
return notificationValue;
});
promise_list.push(last_promise);
return this; return this;
}; };
......
...@@ -2404,5 +2404,38 @@ describe("`RSVP.Queue`", function () { ...@@ -2404,5 +2404,38 @@ describe("`RSVP.Queue`", function () {
done(); done();
}, 20); }, 20);
}); });
it("notify should be propagated until `then`", function (done) {
var queue = new RSVP.Queue(), i = 0, responses = [];
queue.push(function () {
return new RSVP.Promise(function (resolve, reject, notify) {
notify("hello");
});
});
queue.push(null, null, function (notification) {
responses.push(1);
responses.push(notification);
return notification;
});
queue.push(function () {
return;
});
queue.then(null, null, function (notification) {
responses.push(2);
responses.push(notification);
});
setTimeout(function () {
assert.equal(responses[0], 1);
assert.equal(responses[1], "hello", "Notification");
assert.equal(responses[2], 2);
assert.equal(responses[3], "hello", "Notification");
done();
}, 50);
});
}); });
}); });
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