Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async readline/echo and add composer commands #63

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/readline-echo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use Amp\ByteStream\ZlibOutputStream;
use Amp\Loop;
use function Amp\ByteStream\bufferEcho;
use function Amp\ByteStream\readLine;
use function Amp\ByteStream\prompt;

require __DIR__ . "/../vendor/autoload.php";

Loop::run(function () {
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("\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");
Expand Down
6 changes: 3 additions & 3 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ 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.
* Use getStdinLineReader()->getBuffer() to obtain the remaining buffered data.
danog marked this conversation as resolved.
Show resolved Hide resolved
*
* @param string $prompt Optional prompt to print to console
*
* @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) {
if ($prompt) {
Expand Down