1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 12:56:01 +01:00
metamask-extension/app/scripts/lib/nodeify.js

19 lines
491 B
JavaScript
Raw Normal View History

2017-07-13 00:10:52 +02:00
const promiseToCallback = require('promise-to-callback')
const noop = function(){}
module.exports = function nodeify (fn, context) {
2017-07-13 00:06:49 +02:00
return function(){
const args = [].slice.call(arguments)
2017-10-06 22:02:34 +02:00
const lastArg = args[args.length - 1]
const lastArgIsCallback = typeof lastArg === 'function'
let callback
if (lastArgIsCallback) {
callback = lastArg
args.pop()
} else {
callback = noop
}
2017-07-13 00:06:49 +02:00
promiseToCallback(fn.apply(context, args))(callback)
}
}