2016-11-29 02:27:20 +01:00
|
|
|
module.exports = function (promiseFn) {
|
|
|
|
return function () {
|
|
|
|
var args = []
|
|
|
|
for (var i = 0; i < arguments.length - 1; i++) {
|
|
|
|
args.push(arguments[i])
|
2016-11-28 21:43:44 +01:00
|
|
|
}
|
2016-11-29 02:27:20 +01:00
|
|
|
var cb = arguments[arguments.length - 1]
|
2016-11-28 21:43:44 +01:00
|
|
|
|
2016-11-30 00:54:10 +01:00
|
|
|
const nodeified = promiseFn.apply(this, args)
|
|
|
|
|
|
|
|
if (!nodeified) {
|
|
|
|
const methodName = String(promiseFn).split('(')[0]
|
|
|
|
throw new Error(`The ${methodName} did not return a Promise, but was nodeified.`)
|
|
|
|
}
|
|
|
|
nodeified.then(function (result) {
|
2016-11-29 02:27:20 +01:00
|
|
|
cb(null, result)
|
|
|
|
})
|
|
|
|
.catch(function (reason) {
|
|
|
|
cb(reason)
|
|
|
|
})
|
2016-11-30 00:54:10 +01:00
|
|
|
|
|
|
|
return nodeified
|
2016-11-28 21:43:44 +01:00
|
|
|
}
|
|
|
|
}
|