Optimise promisifyRouteParams()

This commit is contained in:
Sébastien Chopin 2016-12-10 12:39:11 +01:00
parent 2d6ac069fd
commit 0c385f522c

View File

@ -37,10 +37,9 @@ exports.promisifyRouteParams = function (fn) {
if (Array.isArray(fn)) { if (Array.isArray(fn)) {
return Promise.resolve(fn) return Promise.resolve(fn)
} }
let promise
// If routeParams[route] is a function expecting a callback // If routeParams[route] is a function expecting a callback
if (fn.length === 1) { if (fn.length === 1) {
promise = new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fn(function (err, routeParams) { fn(function (err, routeParams) {
if (err) { if (err) {
reject(err) reject(err)
@ -48,9 +47,8 @@ exports.promisifyRouteParams = function (fn) {
resolve(routeParams) resolve(routeParams)
}) })
}) })
} else {
promise = fn()
} }
let promise = fn()
if (!(promise instanceof Promise)) { if (!(promise instanceof Promise)) {
promise = Promise.resolve(promise) promise = Promise.resolve(promise)
} }