diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-07-13 06:06:49 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-07-13 06:06:49 +0800 |
commit | da35f6744e3201bb75b896d3127d4f30d7e4d789 (patch) | |
tree | 3db45527e7d8d24a5838d39bdece31888a461be9 /app/scripts/lib | |
parent | 231ad48564758895bace7b0e750cdfa5577128f8 (diff) | |
download | tangerine-wallet-browser-da35f6744e3201bb75b896d3127d4f30d7e4d789.tar tangerine-wallet-browser-da35f6744e3201bb75b896d3127d4f30d7e4d789.tar.gz tangerine-wallet-browser-da35f6744e3201bb75b896d3127d4f30d7e4d789.tar.bz2 tangerine-wallet-browser-da35f6744e3201bb75b896d3127d4f30d7e4d789.tar.lz tangerine-wallet-browser-da35f6744e3201bb75b896d3127d4f30d7e4d789.tar.xz tangerine-wallet-browser-da35f6744e3201bb75b896d3127d4f30d7e4d789.tar.zst tangerine-wallet-browser-da35f6744e3201bb75b896d3127d4f30d7e4d789.zip |
use new nodeify
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/nodeify.js | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/app/scripts/lib/nodeify.js b/app/scripts/lib/nodeify.js index 51d89a8fb..4e111c8b2 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) } } |