Skip to content

Commit df52c40

Browse files
committed
Exit streaming example once all streams have been flushed
1 parent 61cefef commit df52c40

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

examples/exec-stream.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@
2727
$out = new Stream(STDOUT, $loop);
2828
$out->pause();
2929

30-
$client->execCreate($container, $cmd)->then(function ($info) use ($client, $out) {
30+
// unkown exit code by default
31+
$exit = 1;
32+
33+
$client->execCreate($container, $cmd)->then(function ($info) use ($client, $out, &$exit) {
3134
$stream = $client->execStartStream($info['Id']);
3235
$stream->pipe($out);
3336

3437
$stream->on('error', 'printf');
3538

36-
// exit with error code of executed command once it closes
37-
$stream->on('close', function () use ($client, $info) {
38-
$client->execInspect($info['Id'])->then(function ($info) {
39-
exit($info['ExitCode']);
39+
// remember exit code of executed command once it closes
40+
$stream->on('close', function () use ($client, $info, &$exit) {
41+
$client->execInspect($info['Id'])->then(function ($info) use (&$exit) {
42+
$exit = $info['ExitCode'];
4043
}, 'printf');
4144
});
4245
}, 'printf');
4346

4447
$loop->run();
48+
49+
exit($exit);

0 commit comments

Comments
 (0)