aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/nodeify.js
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-07-14 03:48:50 +0800
committerGitHub <noreply@github.com>2017-07-14 03:48:50 +0800
commit9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc (patch)
tree7fcde7cce82116803a9df3586ad5d91fe812d870 /app/scripts/lib/nodeify.js
parent43b7d5f0ebd420d39eb9257b1edc235d58b0099d (diff)
parent7eccf5905a830853bbb1932dde9a7f4536d43f55 (diff)
downloadtangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.tar
tangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.tar.gz
tangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.tar.bz2
tangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.tar.lz
tangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.tar.xz
tangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.tar.zst
tangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.zip
Merge pull request #1617 from MetaMask/nonce-tracker
transaction controller - use nonce-tracker
Diffstat (limited to 'app/scripts/lib/nodeify.js')
-rw-r--r--app/scripts/lib/nodeify.js27
1 files changed, 6 insertions, 21 deletions
diff --git a/app/scripts/lib/nodeify.js b/app/scripts/lib/nodeify.js
index 51d89a8fb..299bfe624 100644
--- a/app/scripts/lib/nodeify.js
+++ b/app/scripts/lib/nodeify.js
@@ -1,24 +1,9 @@
-module.exports = function (promiseFn) {
- return function () {
- var args = []
- for (var i = 0; i < arguments.length - 1; i++) {
- args.push(arguments[i])
- }
- var cb = arguments[arguments.length - 1]
+const promiseToCallback = require('promise-to-callback')
- 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) {
- cb(null, result)
- })
- .catch(function (reason) {
- cb(reason)
- })
-
- return nodeified
+module.exports = function(fn, context) {
+ return function(){
+ const args = [].slice.call(arguments)
+ const callback = args.pop()
+ promiseToCallback(fn.apply(context, args))(callback)
}
}