aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-10-07 05:08:58 +0800
committerGitHub <noreply@github.com>2017-10-07 05:08:58 +0800
commit4a4338c1f4669f621fc39d34b06a77f247c7ce65 (patch)
tree71cd7b38a3040ea6a05a2b632648f5931dcb8dc4 /app/scripts
parentfa11bbf99673bb6b2dd4ad5f291d63ff1358fda6 (diff)
parent0b6dab384fe1153f16575e662fd61dbade3b9d64 (diff)
downloadtangerine-wallet-browser-4a4338c1f4669f621fc39d34b06a77f247c7ce65.tar
tangerine-wallet-browser-4a4338c1f4669f621fc39d34b06a77f247c7ce65.tar.gz
tangerine-wallet-browser-4a4338c1f4669f621fc39d34b06a77f247c7ce65.tar.bz2
tangerine-wallet-browser-4a4338c1f4669f621fc39d34b06a77f247c7ce65.tar.lz
tangerine-wallet-browser-4a4338c1f4669f621fc39d34b06a77f247c7ce65.tar.xz
tangerine-wallet-browser-4a4338c1f4669f621fc39d34b06a77f247c7ce65.tar.zst
tangerine-wallet-browser-4a4338c1f4669f621fc39d34b06a77f247c7ce65.zip
Merge pull request #2305 from MetaMask/nodeify
nodeify - allow callback to be optional
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/lib/nodeify.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/scripts/lib/nodeify.js b/app/scripts/lib/nodeify.js
index 832d6c6d3..d24e92206 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)
}
}