Harden async's parallel against one function returning multiple times
This commit is contained in:
parent
99d3a34790
commit
bdf11a96ca
1 changed files with 8 additions and 4 deletions
12
src/async.js
12
src/async.js
|
@ -39,13 +39,17 @@ function Async() {
|
|||
var threads = arguments;
|
||||
var pending = threads.length;
|
||||
var results = [];
|
||||
var returned = [];
|
||||
return function(f) {
|
||||
var useResult = function(i) {
|
||||
return function(x) {
|
||||
results[i] = x;
|
||||
pending--;
|
||||
if(pending < 1) {
|
||||
f(results);
|
||||
if(!returned[i]) {
|
||||
results[i] = x;
|
||||
returned[i] = true;
|
||||
pending--;
|
||||
if(pending < 1) {
|
||||
f(results);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue