Skip to content

Commit

Permalink
CLI: Wait for both the 'end' and 'close' event to happen before finis…
Browse files Browse the repository at this point in the history
…hing in pbts, see #863
  • Loading branch information
dcodeIO committed Jul 12, 2017
1 parent 31ab863 commit 952c7d1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cli/pbts.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ exports.main = function(args, callback) {
maxBuffer: 1 << 24 // 16mb
});
var out = [];
var ended = false;
var closed = false;
child.stdout.on("data", function(data) {
out.push(data);
});
child.stdout.on("end", function() {
if (closed) finish();
else ended = true;
});
child.stderr.pipe(process.stderr);
child.on("close", function(code) {
// clean up temporary files, no matter what
Expand All @@ -123,6 +129,11 @@ exports.main = function(args, callback) {
throw err;
}

if (ended) finish();
else closed = true;
});

function finish() {
var output = [];
if (argv.global)
output.push(
Expand All @@ -149,7 +160,7 @@ exports.main = function(args, callback) {
return callback(err);
throw err;
}
});
}
}

return undefined;
Expand Down

0 comments on commit 952c7d1

Please sign in to comment.