Commit 426f2a71 authored by Tristan Cavelier's avatar Tristan Cavelier

Promise.all and allOrNone notifies sub progress

parent 335af6dd
......@@ -169,7 +169,6 @@ Promise.all = function (items) {
solver = next.defer();
function succeed(i) {
return function (answer) {
solver.notify(i);
array[i] = answer;
count += 1;
if (count !== items.length) {
......@@ -178,8 +177,13 @@ Promise.all = function (items) {
return solver.resolve(array);
};
}
function notify(i) {
return function (answer) {
solver.notify(i, answer);
};
}
for (i = 0; i < items.length; i += 1) {
Promise.when(items[i], succeed(i), succeed(i));
Promise.when(items[i], succeed(i), succeed(i), notify(i));
}
return next;
};
......@@ -204,7 +208,6 @@ Promise.allOrNone = function (items) {
solver = next.defer();
items.forEach(function (item, i) {
Promise.when(item, function (answer) {
solver.notify(i);
array[i] = answer;
count += 1;
if (count !== items.length) {
......@@ -212,8 +215,9 @@ Promise.allOrNone = function (items) {
}
return solver.resolve(array);
}, function (answer) {
solver.notify(i);
return solver.reject(answer);
}, function (answer) {
solver.notify(i, answer);
});
});
return next;
......
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