mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
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 returned
This commit is contained in:
parent
ca6da2c724
commit
0835bfeabb
1 changed files with 5 additions and 6 deletions
|
@ -82,17 +82,16 @@ async function aCallAll(hook_name, args, cb) {
|
||||||
if (!cb) cb = function () {};
|
if (!cb) cb = function () {};
|
||||||
if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []);
|
if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []);
|
||||||
|
|
||||||
var newArray = [];
|
var hooksPromises = exports.plugins.hooks[hook_name].map(async function(hook, index){
|
||||||
// This should be a map.
|
return await hookCallWrapper(hook, hook_name, args, function (res) {
|
||||||
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);
|
return Promise.resolve(res);
|
||||||
});
|
});
|
||||||
newArray.push(test)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var result = await Promise.all(hooksPromises);
|
||||||
|
|
||||||
// after forEach
|
// after forEach
|
||||||
cb(null, _.flatten(newArray, true));
|
cb(null, _.flatten(result, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return a Promise if cb is not supplied */
|
/* return a Promise if cb is not supplied */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue