Skip to content

Commit

Permalink
formation: ensure ports are fully drained before exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Sep 24, 2019
1 parent fad056c commit 15a0fd3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions chief/private/formation.rkt
Expand Up @@ -107,11 +107,18 @@
(lambda _
(emit 'message (format "process started with pid ~a" pid)))
(lambda _
(let loop ()
(define line (read-line (sync (choice-evt stdout stderr))))
(unless (eof-object? line)
(emit 'message line)
(loop))))
(let loop ([ports (list stdout stderr)])
(define port (sync (apply choice-evt ports)))
(define line (read-line port))
(cond
[(eof-object? line)
(define ports* (remq port ports))
(unless (null? ports*)
(loop ports*))]

[else
(emit 'message line)
(loop ports)])))
(lambda _
(emit 'exit (control 'exit-code))))))

Expand Down

0 comments on commit 15a0fd3

Please sign in to comment.