Skip to content

Commit

Permalink
await on Q fcall methods
Browse files Browse the repository at this point in the history
to catch rejections
  • Loading branch information
splitice committed Mar 16, 2022
1 parent 336e487 commit 6c7aa65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
yarn.lock
yarn.lock
.vscode/
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ Q.cancelledRace = async function(promises, safeRace = true){
}

Q.fcall = function(fn, ...args){
return new QPromise((resolve, reject)=>{
return new QPromise(async (resolve, reject)=>{
try {
resolve(fn(...args))
resolve(await fn(...args))
} catch(ex){
reject(ex)
}
Expand Down Expand Up @@ -220,12 +220,12 @@ Q.deferredTimeout = function(deferred, ms, symbol = undefined, overloadSafe = tr
return deferred.promise
}

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

Q.finvoke = function(object, method, ...args){
return Q.fcall(object[method].bind(object), ...args)
Q.finvoke = async function(object, method, ...args){
return Q.fcall(await object[method].bind(object), ...args)
}

Q.resetUnhandledRejections = function(){}
Expand Down

0 comments on commit 6c7aa65

Please sign in to comment.