Skip to content

Node.js based forum software built for the modern web

fix: remove left over code, use proper names

Barış Soner Uşaklı0ac49d63d910
diff --git a/src/promisify.js b/src/promisify.js
index 6830adc40e..f56e8e68bc 100644
--- a/src/promisify.js
+++ b/src/promisify.js
@@ -17,54 +17,33 @@ 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) {
- if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
- return origFn.apply(null, args);
- }
-
- return promiseFn.apply(null, arguments);
- };
- }
-
- function wrapIt(origFn, callbackFn) {
- return async function wrapper(...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) {
- if (err) {
- return cb(err);
- }
-
- // fixes callbackified functions used in async.waterfall
- if (res !== undefined) {
- return cb(err, res);
- }
- return cb(err);
+ return res !== undefined ? cb(err, res) : cb(err);
});
return callbackFn.apply(null, args);
}
@@ -72,6 +51,17 @@ module.exports = function (theModule, ignoreKeys) {
};
}
+ function wrapPromise(origFn, promiseFn) {
+ return function wrapperPromise(...args) {
+ if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
+ return origFn.apply(null, args);
+ }
+
+ return promiseFn.apply(null, arguments);
+ };
+ }
+
+ var parts = [];
function deprecateRecursive(module, key) {
if (!module) {
return;