Commit 59f199ee authored by Tristan Cavelier's avatar Tristan Cavelier

Promise.all and allOrNone notifies when a promise ended

parent 149198e4
...@@ -168,6 +168,7 @@ Promise.all = function (items) { ...@@ -168,6 +168,7 @@ Promise.all = function (items) {
solver = next.defer(); solver = next.defer();
function succeed(i) { function succeed(i) {
return function (answer) { return function (answer) {
solver.notify(i);
array[i] = answer; array[i] = answer;
count += 1; count += 1;
if (count !== items.length) { if (count !== items.length) {
...@@ -202,6 +203,7 @@ Promise.allOrNone = function (items) { ...@@ -202,6 +203,7 @@ Promise.allOrNone = function (items) {
solver = next.defer(); solver = next.defer();
items.forEach(function (item, i) { items.forEach(function (item, i) {
Promise.when(item, function (answer) { Promise.when(item, function (answer) {
solver.notify(i);
array[i] = answer; array[i] = answer;
count += 1; count += 1;
if (count !== items.length) { if (count !== items.length) {
...@@ -209,6 +211,7 @@ Promise.allOrNone = function (items) { ...@@ -209,6 +211,7 @@ Promise.allOrNone = function (items) {
} }
return solver.resolve(array); return solver.resolve(array);
}, function (answer) { }, function (answer) {
solver.notify(i);
return solver.reject(answer); return solver.reject(answer);
}); });
}); });
......
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