2017-07-12 15:10:52 -07:00
|
|
|
const promiseToCallback = require('promise-to-callback')
|
2016-11-28 12:43:44 -08:00
|
|
|
|
2017-08-03 18:20:01 -07:00
|
|
|
module.exports = function nodeify (fn, context) {
|
2017-07-12 15:06:49 -07:00
|
|
|
return function(){
|
|
|
|
const args = [].slice.call(arguments)
|
|
|
|
const callback = args.pop()
|
2017-08-03 18:20:01 -07:00
|
|
|
if (typeof callback !== 'function') throw new Error('callback is not a function')
|
2017-07-12 15:06:49 -07:00
|
|
|
promiseToCallback(fn.apply(context, args))(callback)
|
2016-11-28 12:43:44 -08:00
|
|
|
}
|
|
|
|
}
|