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

Queue notifications are now enabled

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