diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-06-23 14:09:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-23 14:09:51 -0400 |
commit | e7391046b7a1c74a28d10a08220e39c3af0225a5 (patch) | |
tree | 7433527ba22efc7166113508e793ae470d9f5227 | |
parent | 1706048929a1882c0ee7391065616b15dd9fd621 (diff) | |
parent | 3ef90dac66ca93566ad162765fe24a122cb639cf (diff) | |
download | async-e7391046b7a1c74a28d10a08220e39c3af0225a5.tar.gz |
Merge pull request #1197 from raydog/master
Callback can be called twice in asyncify when using promises.
-rw-r--r-- | lib/asyncify.js | 2 | ||||
-rw-r--r-- | mocha_test/asyncify.js | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/asyncify.js b/lib/asyncify.js index e3f6f87..089f94b 100644 --- a/lib/asyncify.js +++ b/lib/asyncify.js @@ -67,7 +67,7 @@ export default function asyncify(func) { if (isObject(result) && typeof result.then === 'function') { result.then(function(value) { callback(null, value); - })['catch'](function(err) { + }, function(err) { callback(err.message ? err : new Error(err)); }); } else { diff --git a/mocha_test/asyncify.js b/mocha_test/asyncify.js index aae878e..025083a 100644 --- a/mocha_test/asyncify.js +++ b/mocha_test/asyncify.js @@ -74,6 +74,13 @@ describe('asyncify', function(){ 'rsvp' ]; + // Both Bluebird and native promises emit these events. We handle it because Bluebird + // will report these rejections to stderr if we don't, which is a great feature for + // normal cases, but not here, since we expect unhandled rejections: + process.on('unhandledRejection', function () { + // Ignore. + }); + names.forEach(function(name) { describe(name, function() { @@ -111,6 +118,25 @@ describe('asyncify', function(){ done(); }); }); + + it('callback error', function(done) { + var promisified = function(argument) { + return new Promise(function (resolve) { + resolve(argument + " resolved"); + }); + }; + var call_count = 0; + async.asyncify(promisified)("argument", function () { + call_count++; + if (call_count === 1) { + throw new Error("error in callback"); + } + }); + setTimeout(function () { + expect(call_count).to.equal(1); + done(); + }, 15); + }); }); }); }); |