Skip to content

Commit

Permalink
fix(race): Fix hanging processes for incomplete race tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
kofno committed Jan 12, 2019
1 parent eaa3f34 commit c18f313
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,23 @@ class Task<E, T> {

return new Task((reject, resolve) => {
let resolved = false;
const cancels: Array<() => void> = [];

const resolveIf = (result: T) => {
if (!resolved) {
resolved = true;
resolve(result);
cancels.forEach(fn => fn());
}
};
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < ts.length; i++) {
ts[i].fork(reject, resolveIf);
cancels.push(ts[i].fork(reject, resolveIf));
}
return noop;

return () => {
cancels.forEach(fn => fn());
};
});
}

Expand Down

0 comments on commit c18f313

Please sign in to comment.