From d1330a1e1c0fc536244c77605f0612cf4412e9fe Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 17 Jul 2020 10:08:40 +0100 Subject: [PATCH] Bugfix: Async bump part 2 Sorry, not sure what happened but having kids jump all over the keyboard while I do this probably didn't help... :| --- src/package.json | 2 +- src/static/js/pluginfw/hooks.js | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/package.json b/src/package.json index 61f8cce7..d5327a10 100644 --- a/src/package.json +++ b/src/package.json @@ -30,7 +30,7 @@ } ], "dependencies": { - "async": "3.2.0", + "async": "^3.2.0", "async-stacktrace": "0.0.2", "channels": "0.0.4", "cheerio": "0.22.0", diff --git a/src/static/js/pluginfw/hooks.js b/src/static/js/pluginfw/hooks.js index e9700c37..c7a25bca 100644 --- a/src/static/js/pluginfw/hooks.js +++ b/src/static/js/pluginfw/hooks.js @@ -1,4 +1,3 @@ -var async = require("async"); var _ = require("underscore"); exports.bubbleExceptions = true @@ -78,19 +77,22 @@ exports.callAll = function (hook_name, args) { } } -function aCallAll(hook_name, args, cb) { +async function aCallAll(hook_name, args, cb) { if (!args) args = {}; if (!cb) cb = function () {}; if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []); - async.map( - exports.plugins.hooks[hook_name], - function (hook, cb) { - hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); }); - }, - function (err, res) { - cb(null, _.flatten(res, true)); - } - ); + + var newArray = []; + // This should be a map. + await exports.plugins.hooks[hook_name].forEach(async function(hook, index){ + let test = await hookCallWrapper(hook, hook_name, args, function (res) { + return Promise.resolve(res); + }); + newArray.push(test) + }); + + // after forEach + cb(null, _.flatten(newArray, true)); } /* return a Promise if cb is not supplied */