Bugfix: wait promise finish on hooks (#4194)
This commit fixes the error of not waiting the async code to finish. As the forEach did not wait until the async code finish we may get a hook set up incorrectly. To fix it, we use an "Array.map" to iterate and wait the promises to be resolved and then returnedpull/4198/head
parent
ca6da2c724
commit
0835bfeabb
|
@ -82,17 +82,16 @@ async function aCallAll(hook_name, args, cb) {
|
|||
if (!cb) cb = function () {};
|
||||
if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []);
|
||||
|
||||
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) {
|
||||
var hooksPromises = exports.plugins.hooks[hook_name].map(async function(hook, index){
|
||||
return await hookCallWrapper(hook, hook_name, args, function (res) {
|
||||
return Promise.resolve(res);
|
||||
});
|
||||
newArray.push(test)
|
||||
});
|
||||
|
||||
var result = await Promise.all(hooksPromises);
|
||||
|
||||
// after forEach
|
||||
cb(null, _.flatten(newArray, true));
|
||||
cb(null, _.flatten(result, true));
|
||||
}
|
||||
|
||||
/* return a Promise if cb is not supplied */
|
||||
|
|
Loading…
Reference in New Issue