diff options
author | kumavis <aaron@kumavis.me> | 2017-10-07 03:36:08 +0800 |
---|---|---|
committer | kumavis <aaron@kumavis.me> | 2017-10-07 03:36:08 +0800 |
commit | be4f7b33f4f0885f2c0f5f4d537f6e9793f3fa30 (patch) | |
tree | 79719085f7de3687f32036535e800cd055356b71 | |
parent | 35f4148343cf4400f7a38eef07282cae44cd0335 (diff) | |
download | tangerine-wallet-browser-be4f7b33f4f0885f2c0f5f4d537f6e9793f3fa30.tar.gz tangerine-wallet-browser-be4f7b33f4f0885f2c0f5f4d537f6e9793f3fa30.tar.zst tangerine-wallet-browser-be4f7b33f4f0885f2c0f5f4d537f6e9793f3fa30.zip |
nodeify - allow callback to be optional
-rw-r--r-- | app/scripts/lib/nodeify.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/app/scripts/lib/nodeify.js b/app/scripts/lib/nodeify.js index 832d6c6d3..19c3c8337 100644 --- a/app/scripts/lib/nodeify.js +++ b/app/scripts/lib/nodeify.js @@ -1,10 +1,18 @@ const promiseToCallback = require('promise-to-callback') +const noop = function(){} module.exports = function nodeify (fn, context) { return function(){ const args = [].slice.call(arguments) - const callback = args.pop() - if (typeof callback !== 'function') throw new Error('callback is not a function') + const lastArg = args[args.length-1] + const lastArgIsCallback = typeof lastArg === 'function' + let callback + if (lastArgIsCallback) { + callback = lastArg + args.pop() + } else { + callback = noop + } promiseToCallback(fn.apply(context, args))(callback) } } |