8000 Fix: Avoid swallowing thrown errors in callback argument (closes #43) · gulpjs/async-done@204de69 · GitHub
[go: up one dir, main page]

Skip to content

Commit 204de69

Browse files
committed
Fix: Avoid swallowing thrown errors in callback argument (closes #43)
1 parent 77d00f9 commit 204de69

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var domain = require('domain');
44

55
var eos = require('end-of-stream');
6-
var tick = require('next-tick');
6+
var tick = require('process-nextick-args');
77
var once = require('once');
88
var exhaust = require('stream-exhaust');
99

@@ -25,14 +25,14 @@ function asyncDone(fn, cb) {
2525
}
2626

2727
function onSuccess(result) {
28-
return done(null, result);
28+
tick(done, null, result);
2929
}
3030

3131
function onError(error) {
3232
if (!error) {
3333
error = new Error('Promise rejected without Error');
3434
}
35-
return done(error);
35+
tick(done, error);
3636
}
3737

3838
function asyncRunner() {
@@ -43,7 +43,7 @@ function asyncDone(fn, cb) {
4343
}
4444

4545
function onCompleted() {
46-
return onSuccess(onNext.state);
46+
onSuccess(onNext.state);
4747
}
4848

4949
if (result && typeof result.on === 'function') {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
},
2828
"dependencies": {
2929
"end-of-stream": "^1.1.0",
30-
"next-tick": "^1.0.0",
3130
"once": "^1.3.2",
31+
"process-nextick-args": "^1.0.7",
3232
"stream-exhaust": "^1.0.1"
3333
},
3434
"devDependencies": {

test/promises.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var domain = require('domain');
4+
35
var expect = require('expect');
46

57
var when = require('when');
@@ -41,4 +43,17 @@ describe('promises', function() {
4143
done();
4244
});
4345
});
46+
47+
it('does not swallow thrown errors in callback', function(done) {
48+
var d = domain.create();
49+
d.once('error', function(err) {
50+
expect(err).toExist();
51+
done();
52+
});
53+
d.run(function() {
54+
asyncDone(success, function() {
55+
throw new Error('Boom');
56+
});
57+
});
58+
});
4459
});

0 commit comments

Comments
 (0)
0