Permalink
Browse files

check pending before calling hub.close()

  • Loading branch information...
1 parent 84851fe commit cafdc6c2ebf18e6a14a49449b2d950a681e2272c @substack committed Aug 1, 2012
Showing with 24 additions and 21 deletions.
  1. +24 −21 bin/exec.js
View
45 bin/exec.js
@@ -48,28 +48,31 @@ function spawn (hub, opts) {
if (err) {
console.error(err)
p.hub.close();
+ return;
}
- else {
- em.on('stdout', function (buf, proc) {
- if (procs[proc.drone] !== proc.id) return;
- console.log(
- '[' + proc.drone + '#' + proc.id + '] '
- + buf.replace(/\n$/, '')
- );
- });
- em.on('stderr', function (buf, proc) {
- if (procs[proc.drone] !== proc.id) return;
- console.log(
- '[' + proc.drone + '#' + proc.id + '] '
- + buf.replace(/\n$/, '')
- );
- });
- em.on('exit', function (code, sig, proc) {
- if (procs[proc.drone] !== proc.id) return;
- console.log('(' + proc.drone + '#' + proc.id + ' exited)');
- p.hub.close();
- });
- }
+
+ em.on('stdout', function (buf, proc) {
+ if (procs[proc.drone] !== proc.id) return;
+ console.log(
+ '[' + proc.drone + '#' + proc.id + '] '
+ + buf.replace(/\n$/, '')
+ );
+ });
+ em.on('stderr', function (buf, proc) {
+ if (procs[proc.drone] !== proc.id) return;
+ console.log(
+ '[' + proc.drone + '#' + proc.id + '] '
+ + buf.replace(/\n$/, '')
+ );
+ });
+
+ var pending = Object.keys(procs).length;
+ em.on('exit', function (code, sig, proc) {
+ if (procs[proc.drone] !== proc.id) return;
+ console.log('(' + proc.drone + '#' + proc.id + ' exited)');
+
+ if (--pending === 0) p.hub.close();
+ });
});
});
}

0 comments on commit cafdc6c

Please sign in to comment.