From 3fbaff5678b6ecc1710d956a543971932a7ca8d6 Mon Sep 17 00:00:00 2001 From: Mathew Heard Date: Wed, 30 Nov 2022 22:23:27 +1100 Subject: [PATCH] fix promise rejection on throatqueuefunction runing --- lib/ThroatQueueFunction.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ThroatQueueFunction.js b/lib/ThroatQueueFunction.js index 17f6b0d..986ff67 100644 --- a/lib/ThroatQueueFunction.js +++ b/lib/ThroatQueueFunction.js @@ -44,16 +44,20 @@ function ThroatQueueFunction(n = 5){ const r = rFn() const d = Q.defer() + const dTrack = Q.defer() const rr = d.promise - rr.id = idObj - rr.fn = what - rr.cancel = ()=>{ + dTrack.promise.id = rr.id = idObj + dTrack.promise.fn = rr.fn = what + dTrack.promise.cancel = rr.cancel = ()=>{ cancellationState.cancel() } - running.push(rr) + running.push(dTrack.promise) try { - d.resolve(await r) + const fnResult = await r + dTrack.resolve() + d.resolve(fnResult) } catch(ex) { + dTrack.resolve() d.reject(ex) }