From c18f31317141dc957e83b37114fee52398d1473a Mon Sep 17 00:00:00 2001 From: "Ryan L. Bell" Date: Sat, 12 Jan 2019 18:49:24 -0500 Subject: [PATCH] fix(race): Fix hanging processes for incomplete race tasks --- src/Task.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Task.ts b/src/Task.ts index 650a5e4..c8cd5d0 100644 --- a/src/Task.ts +++ b/src/Task.ts @@ -86,17 +86,23 @@ class Task { 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()); + }; }); }