Skip to content

Commit

Permalink
Stop loop when the streams close
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Mar 19, 2016
1 parent d7a2cce commit 8b4e8c6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,23 @@ public static function parent(
*/
public static function child(LoopInterface $loop, array $options = [], $termiteCallable = null)
{
$messenger = new Messenger(new Stream(STDIN, $loop), new Stream(STDOUT, $loop), new Stream(STDERR, $loop), [
$stdin = new Stream(STDIN, $loop);
$stdout = new Stream(STDOUT, $loop);
$stderr = new Stream(STDERR, $loop);

$messenger = new Messenger($stdin, $stdout, $stderr, [
'read' => 'stdin',
'write_err' => 'stderr',
'write' => 'stdout',
] + $options);

$closeNStop = function () use ($loop) {
$loop->stop();
};
$stdin->on('close', $closeNStop);
$stdout->on('close', $closeNStop);
$stderr->on('close', $closeNStop);

if ($termiteCallable === null) {
$termiteCallable = function () use ($loop) {
$loop->addTimer(
Expand Down

0 comments on commit 8b4e8c6

Please sign in to comment.