From be8983e719c93315d584b60b1d8af11680599398 Mon Sep 17 00:00:00 2001 From: Mathew Date: Tue, 5 Sep 2023 13:43:23 +1000 Subject: [PATCH] prevent a promise leak if any of the running resolve first --- lib/ThroatQueueFunction.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ThroatQueueFunction.js b/lib/ThroatQueueFunction.js index 986ff67..cb68f3f 100644 --- a/lib/ThroatQueueFunction.js +++ b/lib/ThroatQueueFunction.js @@ -8,7 +8,11 @@ function ThroatQueueFunction(n = 5){ const deferred = Q.defer() cancellationState.deferredWrap(deferred) running = [...running, deferred.promise] - await Q.safeRace(running) + try { + await Q.safeRace(running) + } finally { + deferred.resolve(null) + } } let ret = async function(cancellationState, what){ if(what === null){