From 9c9247fe8283b22e00a254746bf822da4b0b5ea4 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Mon, 9 Jan 2023 22:32:38 +0100 Subject: [PATCH] Simplify ping-many example --- examples/ping-many.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/examples/ping-many.php b/examples/ping-many.php index 3dd452b..7c887af 100644 --- a/examples/ping-many.php +++ b/examples/ping-many.php @@ -5,26 +5,20 @@ use Amp\Future; use Amp\Process\Process; use function Amp\async; +use function Amp\ByteStream\getStdout; function show_process_output(Process $process): void { - $stream = $process->getStdout(); - - while (null !== $chunk = $stream->read()) { - echo $chunk; - } + Amp\ByteStream\pipe($process->getStdout(), getStdout()); $code = $process->join(); $pid = $process->getPid(); - echo "Process {$pid} exited with {$code}\n"; + getStdout()->write("Process {$pid} exited with {$code}\n"); } -$hosts = ['8.8.8.8', '8.8.4.4', 'google.com', 'stackoverflow.com', 'github.com']; - $futures = []; - -foreach ($hosts as $host) { +foreach (['8.8.8.8', '8.8.4.4', 'google.com', 'stackoverflow.com', 'github.com'] as $host) { $command = \DIRECTORY_SEPARATOR === "\\" ? "ping -n 5 {$host}" : "ping -c 5 {$host}";