mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
fix: remove left over code, use proper names
This commit is contained in:
@@ -17,32 +17,42 @@ module.exports = function (theModule, ignoreKeys) {
|
||||
return fn && fn.constructor && fn.constructor.name === 'AsyncFunction';
|
||||
}
|
||||
|
||||
var parts = [];
|
||||
function promisifyRecursive(module, key) {
|
||||
|
||||
function promisifyRecursive(module) {
|
||||
if (!module) {
|
||||
return;
|
||||
}
|
||||
if (key) {
|
||||
parts.push(key);
|
||||
}
|
||||
|
||||
var keys = Object.keys(module);
|
||||
keys.forEach(function (key) {
|
||||
if (ignoreKeys.includes(key)) {
|
||||
return;
|
||||
}
|
||||
if (isAsyncFunction(module[key])) {
|
||||
module[key] = wrapIt(module[key], util.callbackify(module[key]));
|
||||
module[key] = wrapCallback(module[key], util.callbackify(module[key]));
|
||||
} else if (isCallbackedFunction(module[key])) {
|
||||
module[key] = wrapTwo(module[key], util.promisify(module[key]));
|
||||
module[key] = wrapPromise(module[key], util.promisify(module[key]));
|
||||
} else if (typeof module[key] === 'object') {
|
||||
promisifyRecursive(module[key], key);
|
||||
promisifyRecursive(module[key]);
|
||||
}
|
||||
});
|
||||
parts.pop();
|
||||
}
|
||||
|
||||
function wrapTwo(origFn, promiseFn) {
|
||||
return function wrapper2(...args) {
|
||||
function wrapCallback(origFn, callbackFn) {
|
||||
return async function wrapperCallback(...args) {
|
||||
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
|
||||
const cb = args.pop();
|
||||
args.push(function (err, res) {
|
||||
return res !== undefined ? cb(err, res) : cb(err);
|
||||
});
|
||||
return callbackFn.apply(null, args);
|
||||
}
|
||||
return origFn.apply(null, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
function wrapPromise(origFn, promiseFn) {
|
||||
return function wrapperPromise(...args) {
|
||||
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
|
||||
return origFn.apply(null, args);
|
||||
}
|
||||
@@ -51,27 +61,7 @@ module.exports = function (theModule, ignoreKeys) {
|
||||
};
|
||||
}
|
||||
|
||||
function wrapIt(origFn, callbackFn) {
|
||||
return async function wrapper(...args) {
|
||||
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
|
||||
const cb = args.pop();
|
||||
args.push(function (err, res) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// fixes callbackified functions used in async.waterfall
|
||||
if (res !== undefined) {
|
||||
return cb(err, res);
|
||||
}
|
||||
return cb(err);
|
||||
});
|
||||
return callbackFn.apply(null, args);
|
||||
}
|
||||
return origFn.apply(null, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
var parts = [];
|
||||
function deprecateRecursive(module, key) {
|
||||
if (!module) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user