From 6c7aa65a05d1b402742231b1a38c4eea9af15651 Mon Sep 17 00:00:00 2001 From: Mathew Heard Date: Wed, 16 Mar 2022 20:26:56 +1100 Subject: [PATCH] await on Q fcall methods to catch rejections --- .gitignore | 3 ++- index.js | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 167ab9f..2ee71e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ -yarn.lock \ No newline at end of file +yarn.lock +.vscode/ \ No newline at end of file diff --git a/index.js b/index.js index 8f842b6..33a4787 100644 --- a/index.js +++ b/index.js @@ -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) } @@ -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(){}