Skip to content

Commit

Permalink
fix promise rejection on throatqueuefunction runing
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Nov 30, 2022
1 parent 764a969 commit 3fbaff5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/ThroatQueueFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 3fbaff5

Please sign in to comment.