From 0c385f522ca3853cce8cd893619a33c24a8da817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Sat, 10 Dec 2016 12:39:11 +0100 Subject: [PATCH] Optimise promisifyRouteParams() --- lib/utils.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 6cde738d13..f6aa4ef0e6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -37,10 +37,9 @@ exports.promisifyRouteParams = function (fn) { if (Array.isArray(fn)) { return Promise.resolve(fn) } - let promise // If routeParams[route] is a function expecting a callback if (fn.length === 1) { - promise = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { fn(function (err, routeParams) { if (err) { reject(err) @@ -48,9 +47,8 @@ exports.promisifyRouteParams = function (fn) { resolve(routeParams) }) }) - } else { - promise = fn() } + let promise = fn() if (!(promise instanceof Promise)) { promise = Promise.resolve(promise) }