hooks: Inline `aCallFirst()` into `exports.aCallFirst()`

pull/4698/head
Richard Hansen 2021-02-01 00:34:49 -05:00 committed by John McLear
parent 77f480d954
commit fd5d3ce777
1 changed files with 4 additions and 7 deletions

View File

@ -362,7 +362,10 @@ exports.callFirst = (hookName, context) => {
return [];
};
const aCallFirst = async (hookName, context, predicate = null) => {
exports.aCallFirst = async (hookName, context, cb = null, predicate = null) => {
if (cb != null) {
return await attachCallback(exports.aCallFirst(hookName, context, null, predicate), cb);
}
if (!context) context = {};
if (predicate == null) predicate = (val) => val.length;
const hooks = pluginDefs.hooks[hookName] || [];
@ -373,12 +376,6 @@ const aCallFirst = async (hookName, context, predicate = null) => {
return [];
};
/* return a Promise if cb is not supplied */
exports.aCallFirst = (hookName, context, cb, predicate) => {
if (cb == null) return aCallFirst(hookName, context, predicate);
util.callbackify(aCallFirst)(hookName, context, predicate, cb);
};
exports.exportedForTestingOnly = {
callHookFnAsync,
callHookFnSync,