Skip to content

Commit

Permalink
deferred timeout method
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Oct 12, 2021
1 parent 9099c58 commit 58c25fa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ Q.timeout = function (promise, ms, message = undefined){
return deferred.promise
}

Q.deferredTimeout = function(deferred, ms, symbol = undefined){
if(!symbol) {
symbol = new Error(`Timed out after ${ms} ms`)
}
const timer = setTimeout(()=>{
deferred.reject(symbol)
}, ms)

deferred.catch(()=>{}).then(()=>{
clearTimeout(timer)
})

return deferred.promise
}

Q.ninvoke = function(object, method, ...args){
return Q.nfcall(object[method].bind(object), ...args)
}
Expand Down

0 comments on commit 58c25fa

Please sign in to comment.