Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

only exit after stdin and stderr are flushed

  • Loading branch information...
commit c0eedaa5e1816bbeea0d25b9a5d186f61701d6ff 1 parent 9f934ca
@bkw bkw authored
Showing with 12 additions and 6 deletions.
  1. +12 −6 lib/encoder.js
View
18 lib/encoder.js
@@ -28,7 +28,8 @@ Encoder.prototype.default_options = {
Encoder.prototype.encode = function(value, path, options)
{
// preserve scope in callbacks with self
- var self = this, cmd_options, qrencode_args, stdout, stderr, qrencode;
+ var self = this,
+ cmd_options, qrencode_args, stdout, stderr, qrencode, exitcode;
try {
// check for undefined value
@@ -88,13 +89,18 @@ Encoder.prototype.encode = function(value, path, options)
stderr = data;
});
- // add listener for process exist and emit end or error event
- // depending on exit code
+ // add listener for process exit and save exit code
qrencode.on('exit', function(code) {
- if(code == 0) {
- self.emit('end', stdout);
- } else {
+ exitcode = code;
+ });
+
+ // add listener for filehandle close and emit end or error event
+ // depending on exit code
+ qrencode.on('close', function() {
+ if(exitcode !== 0) {
self.emit('error', new Error(stderr));
+ } else {
+ self.emit('end', stdout);
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.