1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 11:54:54 +01:00
This commit is contained in:
Daniil Gentili 2019-08-22 22:42:20 +02:00
parent 010c215c4b
commit 4b7bd7b8ee
2 changed files with 5 additions and 5 deletions

View File

@ -5,13 +5,13 @@ use Amp\ByteStream\ResourceOutputStream;
use Amp\ByteStream\ZlibOutputStream; use Amp\ByteStream\ZlibOutputStream;
use Amp\Loop; use Amp\Loop;
use function Amp\ByteStream\bufferEcho; use function Amp\ByteStream\bufferEcho;
use function Amp\ByteStream\readLine; use function Amp\ByteStream\prompt;
require __DIR__ . "/../vendor/autoload.php"; require __DIR__ . "/../vendor/autoload.php";
Loop::run(function () { Loop::run(function () {
yield bufferEcho("Hello from async PHP!\n"); yield bufferEcho("Hello from async PHP!\n");
$question = yield readLine("What is your question? "); $question = yield prompt("What is your question? ");
yield bufferEcho("I see your question is $question.\n"); yield bufferEcho("I see your question is $question.\n");
yield bufferEcho("\nUnfortunately, I'm just a small script and I can't answer that, feel free to contact us at #amphp on freenode though!\n\n"); yield bufferEcho("\nUnfortunately, I'm just a small script and I can't answer that, feel free to contact us at #amphp on freenode though!\n\n");
yield bufferEcho("Bye!\n\n"); yield bufferEcho("Bye!\n\n");

View File

@ -177,9 +177,9 @@ function getStderr(): ResourceOutputStream
/** /**
* Buffered async readline function. * Buffered async version of the readline() function.
* *
* Please note that this function will hungrily eat data from stdin, * Please note that this function will hungrily eat data from stdin,
* buffering data even after the first newline. * buffering data even after the first newline.
* Use getStdinLineReader()->getBuffer() to obtain the remaining buffered data. * Use getStdinLineReader()->getBuffer() to obtain the remaining buffered data.
* *
@ -187,7 +187,7 @@ function getStderr(): ResourceOutputStream
* *
* @return \Amp\Promise Will resolve with the read line * @return \Amp\Promise Will resolve with the read line
*/ */
function readLine(string $prompt = ''): Promise function prompt(string $prompt = ''): Promise
{ {
return call(static function () use ($prompt) { return call(static function () use ($prompt) {
if ($prompt) { if ($prompt) {