Skip to content

Commit

Permalink
also set context in an error scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Jan 10, 2018
1 parent 0ae1658 commit c27cc33
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ var eos = function(stream, opts, callback) {
callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
};

var onerror = function(err) {
callback.call(stream, err);
};

var onclose = function() {
if (readable && !(rs && rs.ended)) return callback.call(stream, new Error('premature close'));
if (writable && !(ws && ws.ended)) return callback.call(stream, new Error('premature close'));
Expand All @@ -62,7 +66,7 @@ var eos = function(stream, opts, callback) {

stream.on('end', onend);
stream.on('finish', onfinish);
if (opts.error !== false) stream.on('error', callback);
if (opts.error !== false) stream.on('error', onerror);
stream.on('close', onclose);

return function() {
Expand All @@ -75,7 +79,7 @@ var eos = function(stream, opts, callback) {
stream.removeListener('finish', onfinish);
stream.removeListener('exit', onexit);
stream.removeListener('end', onend);
stream.removeListener('error', callback);
stream.removeListener('error', onerror);
stream.removeListener('close', onclose);
};
};
Expand Down

0 comments on commit c27cc33

Please sign in to comment.