From 91dc2ec100629b99cf54b77c5f5b81fd1594096a Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Mon, 15 Oct 2018 09:55:15 -0500 Subject: [PATCH] Update examples --- composer.json | 2 +- examples/basic-command.php | 6 +++--- examples/ping-many.php | 5 +++-- examples/watch-live.php | 2 +- examples/write-command.php | 6 +++--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 288a33a..662f859 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "php": ">=7", "amphp/amp": "^2", - "amphp/byte-stream": "^1.2" + "amphp/byte-stream": "^1.4" }, "require-dev": { "phpunit/phpunit": "^6", diff --git a/examples/basic-command.php b/examples/basic-command.php index 410085c..bebe4e2 100644 --- a/examples/basic-command.php +++ b/examples/basic-command.php @@ -2,7 +2,7 @@ include \dirname(__DIR__) . "/vendor/autoload.php"; -use Amp\ByteStream\Message; +use Amp\ByteStream; use Amp\Process\Process; Amp\Loop::run(function () { @@ -10,9 +10,9 @@ Amp\Loop::run(function () { $command = DIRECTORY_SEPARATOR === "\\" ? "cmd /c echo Hello World!" : "echo 'Hello, world!'"; $process = new Process($command); - $process->start(); + yield $process->start(); - echo yield new Message($process->getStdout()); + echo yield ByteStream\buffer($process->getStdout()); $code = yield $process->join(); echo "Process exited with {$code}.\n"; diff --git a/examples/ping-many.php b/examples/ping-many.php index 0bd0a89..d508f6a 100644 --- a/examples/ping-many.php +++ b/examples/ping-many.php @@ -7,6 +7,8 @@ use function Amp\Promise\all; function show_process_output(Process $process): \Generator { + yield $process->start(); + $stream = $process->getStdout(); while (null !== $chunk = yield $stream->read()) { @@ -14,7 +16,7 @@ function show_process_output(Process $process): \Generator } $code = yield $process->join(); - $pid = yield $process->getPid(); + $pid = $process->getPid(); echo "Process {$pid} exited with {$code}\n"; } @@ -29,7 +31,6 @@ Amp\Loop::run(function () { ? "ping -n 5 {$host}" : "ping -c 5 {$host}"; $process = new Process($command); - $process->start(); $promises[] = new Amp\Coroutine(show_process_output($process)); } diff --git a/examples/watch-live.php b/examples/watch-live.php index 1af5eeb..b93b68f 100644 --- a/examples/watch-live.php +++ b/examples/watch-live.php @@ -10,7 +10,7 @@ Amp\Loop::run(function () { ? "cmd /c echo 1 & ping -n 2 127.0.0.1 > nul & echo 2 & ping -n 2 127.0.0.1 > nul & echo 3 & exit 42" : "echo 1; sleep 1; echo 2; sleep 1; echo 3; exit 42"; $process = new Process($command); - $process->start(); + yield $process->start(); $stream = $process->getStdout(); diff --git a/examples/write-command.php b/examples/write-command.php index 149260d..e264526 100644 --- a/examples/write-command.php +++ b/examples/write-command.php @@ -2,7 +2,7 @@ include \dirname(__DIR__) . "/vendor/autoload.php"; -use Amp\ByteStream\Message; +use Amp\ByteStream; use Amp\Process\Process; Amp\Loop::run(function () { @@ -12,12 +12,12 @@ Amp\Loop::run(function () { } $process = new Process('read; echo "$REPLY"'); - $process->start(); + yield $process->start(); /* send to stdin */ $process->getStdin()->write("abc\n"); - echo yield new Message($process->getStdout()); + echo yield ByteStream\buffer($process->getStdout()); $code = yield $process->join(); echo "Process exited with {$code}.\n";