Merge pull request #896 from MetaMask/i893-DenodeifyKeyringController
Denodeify most of KeyringControllerfeature/default_network_editable
commit
f8fbeb88ff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,17 @@ |
||||
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] |
||||
|
||||
return promiseFn.apply(this, args) |
||||
.then(function (result) { |
||||
cb(null, result) |
||||
}) |
||||
.catch(function (reason) { |
||||
cb(reason) |
||||
}) |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
const assert = require('assert') |
||||
const nodeify = require('../../app/scripts/lib/nodeify') |
||||
|
||||
describe.only('nodeify', function() { |
||||
|
||||
var obj = { |
||||
foo: 'bar', |
||||
promiseFunc: function (a) { |
||||
var solution = this.foo + a |
||||
return Promise.resolve(solution) |
||||
} |
||||
} |
||||
|
||||
it('should retain original context', function(done) { |
||||
var nodified = nodeify(obj.promiseFunc).bind(obj) |
||||
nodified('baz', function (err, res) { |
||||
assert.equal(res, 'barbaz') |
||||
done() |
||||
}) |
||||
}) |
||||
|
||||
}) |
Loading…
Reference in new issue