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 protobufjs#863
  • Loading branch information
dcodeIO authored and Szpadel committed Jul 25, 2017
1 parent afe3d14 commit 548b1bd
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 548b1bd

Please sign in to comment.