Skip to content

Commit

Permalink
Fix: Ensure stream is flowing using stream-exhaust module (fixes #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed May 17, 2016
1 parent 95a1ea6 commit b6b297f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var domain = require('domain');
var eos = require('end-of-stream');
var tick = require('next-tick');
var once = require('once');
var exhaust = require('stream-exhaust');

function noop(){}

Expand Down Expand Up @@ -35,7 +36,7 @@ function asyncDone(fn, cb){
if(result && typeof result.on === 'function'){
// assume node stream
d.add(result);
eos(result, { error: false }, onSuccess);
eos(exhaust(result), { error: false }, onSuccess);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"dependencies": {
"end-of-stream": "^0.1.4",
"next-tick": "^0.2.2",
"once": "^1.3.0"
"once": "^1.3.0",
"stream-exhaust": "^1.0.0"
},
"devDependencies": {
"tap": "~0.4.8",
Expand Down
14 changes: 12 additions & 2 deletions test/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function failure(){
return read.pipe(new EndStream());
}

function unpiped(){
return fs.createReadStream(exists);
}

test('handle a successful stream', function(t){
asyncDone(success, function(err){
t.ok(err == null, 'error should be null or undefined');
Expand All @@ -45,11 +49,17 @@ test('handle an errored stream', function(t){
});

test('handle a returned stream and cb by only calling callback once', function(t){
t.plan(1);

asyncDone(function(cb){
return success().on('end', function(){ cb(); });
}, function(err){
t.ok(err == null, 'error should be null or undefined');
t.end();
});
});

test('consumes an unpiped readable stream', function(t){
asyncDone(unpiped, function(err){
t.ok(err == null, 'error should be null or undefined');
t.end();
});
});

0 comments on commit b6b297f

Please sign in to comment.