Skip to content

Commit

Permalink
Ensure completion of Readable streams returned by tasks
Browse files Browse the repository at this point in the history
If a task returns a Readable stream, ensure that it processes to completion.
stream-consume module is used for this purpose.

Also: end-of-stream was previously reporting completion if a Writable or
Readable completion event was received. Be more discerning: if it's a
Readable stream, require Readable completion. If it's not Readable but
is Writable, require Writable completion. This prevents premature task
termination while, e.g., a Transform stream is still processing.
  • Loading branch information
aroneous committed Jul 21, 2014
1 parent 18831d3 commit 1d9926d
Show file tree
Hide file tree
Showing 3 changed files with 386 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/runTask.js
Expand Up @@ -3,6 +3,7 @@
"use strict";

var eos = require('end-of-stream');
var consume = require('stream-consume');

module.exports = function (task, done) {
var that = this, finish, cb, isDone = false, start, r;
Expand Down Expand Up @@ -47,10 +48,13 @@ module.exports = function (task, done) {
} else if (r && typeof r.pipe === 'function') {
// wait for stream to end

eos(r, { error: true, readable: false, writable: false }, function(err){
eos(r, { error: true, readable: r.readable, writable: r.writable && !r.readable }, function(err){
finish(err, 'stream');
});

// Ensure that the stream completes
consume(r);

} else if (task.length === 0) {
// synchronous, function took in args.length parameters, and the callback was extra
finish(null, 'sync');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -14,7 +14,8 @@
],
"dependencies": {
"end-of-stream": "~0.1.5",
"sequencify": "~0.0.7"
"sequencify": "~0.0.7",
"stream-consume": "~0.1.0"
},
"devDependencies": {
"event-stream": "~3.1.5",
Expand Down

0 comments on commit 1d9926d

Please sign in to comment.