mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 17:36:14 -04:00
hooks: New callAllSerial()
function
This is necessary to migrate away from `callAll()` (which only supports synchronous hook functions).
This commit is contained in:
parent
763fe6fc26
commit
05e0e8dbf7
2 changed files with 102 additions and 1 deletions
|
@ -175,6 +175,8 @@ const callHookFnSync = (hook, context) => {
|
|||
return outcome.val;
|
||||
};
|
||||
|
||||
// DEPRECATED: Use `callAllSerial()` or `aCallAll()` instead.
|
||||
//
|
||||
// Invokes all registered hook functions synchronously.
|
||||
//
|
||||
// Arguments:
|
||||
|
@ -317,7 +319,10 @@ const callHookFnAsync = async (hook, context) => {
|
|||
});
|
||||
};
|
||||
|
||||
// Invokes all registered hook functions asynchronously.
|
||||
// Invokes all registered hook functions asynchronously and concurrently. This is NOT the async
|
||||
// equivalent of `callAll()`: `callAll()` calls the hook functions serially (one at a time) but this
|
||||
// function calls them concurrently. Use `callAllSerial()` if the hook functions must be called one
|
||||
// at a time.
|
||||
//
|
||||
// Arguments:
|
||||
// * hookName: Name of the hook to invoke.
|
||||
|
@ -344,6 +349,19 @@ exports.aCallAll = async (hookName, context, cb = null) => {
|
|||
return flatten1(results);
|
||||
};
|
||||
|
||||
// Like `aCallAll()` except the hook functions are called one at a time instead of concurrently.
|
||||
// Only use this function if the hook functions must be called one at a time, otherwise use
|
||||
// `aCallAll()`.
|
||||
exports.callAllSerial = async (hookName, context) => {
|
||||
if (context == null) context = {};
|
||||
const hooks = pluginDefs.hooks[hookName] || [];
|
||||
const results = [];
|
||||
for (const hook of hooks) {
|
||||
results.push(normalizeValue(await callHookFnAsync(hook, context)));
|
||||
}
|
||||
return flatten1(results);
|
||||
};
|
||||
|
||||
// DEPRECATED: Use `aCallFirst()` instead.
|
||||
//
|
||||
// Like `aCallFirst()`, but synchronous. Hook functions must provide their values synchronously.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue