Harden Async's parallel against one call returning several times

This commit is contained in:
Tissevert 2019-01-13 20:29:48 +01:00
parent 75f02b2c0b
commit 52a7e883fa

View file

@ -39,14 +39,18 @@ function Async() {
var threads = arguments;
var pending = threads.length;
var results = [];
var returned = [];
return function(f) {
var useResult = function(i) {
return function(x) {
if(!returned[i]) {
results[i] = x;
returned[i] = true;
pending--;
if(pending < 1) {
f(results);
}
}
};
};
for(var i = 0; i < threads.length; i++) {