From 22d7f80ab4c5fa4c83f5918d9e517995d73f9a28 Mon Sep 17 00:00:00 2001 From: ochicf Date: Mon, 14 May 2018 20:26:19 +0200 Subject: [PATCH] check for async context start after callback is run --- packages/vulcan-lib/lib/modules/callbacks.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/vulcan-lib/lib/modules/callbacks.js b/packages/vulcan-lib/lib/modules/callbacks.js index 144d9e676..11b9c8cfd 100644 --- a/packages/vulcan-lib/lib/modules/callbacks.js +++ b/packages/vulcan-lib/lib/modules/callbacks.js @@ -99,6 +99,9 @@ export const runCallbacks = function () { if (registeredHook && registeredHook.runs === 'sync') { console.log(`// Warning! Async callback [${callback.name}] executed in sync hook [${hook}], its value is being skipped.`); return accumulator; + } else if (!asyncContext) { + debug(`\x1b[32m>> Started async context in hook [${hook}] by [${callback.name}]\x1b[0m`); + asyncContext = true; } } return result; @@ -115,12 +118,8 @@ export const runCallbacks = function () { } }; - return callbacks.reduce(function (accumulator, callback, index) { + return callbacks.reduce(function (accumulator, callback) { if (Utils.isPromise(accumulator)) { - if (!asyncContext) { - debug(`\x1b[32m>> Started async context in hook [${hook}] by [${callbacks[index-1].name}]\x1b[0m`); - asyncContext = true; - } return new Promise((resolve, reject) => { accumulator .then(result => {