react-shell/examples/timers.php

21 lines
503 B
PHP
Raw Permalink Normal View History

2024-02-27 01:08:29 +00:00
<?php
use React\EventLoop\Loop;
2024-02-27 01:22:49 +00:00
require_once __DIR__."/../vendor/autoload.php";
2024-02-27 01:08:29 +00:00
$shell = new NoccyLabs\React\Shell\Shell();
2024-02-27 01:22:49 +00:00
$shell->on('prompt', function ($shell) {
2024-02-27 01:08:29 +00:00
$shell->setPrompt(date("H:i:s> "));
});
$shell->on('input', function (array $input) use ($shell) {
$shell->write("You entered: ".join(" ", $input)."\n");
});
// The shell is an OutputStream
$shell->write("Hello World!\n\n");
Loop::addPeriodicTimer(5, function () use ($shell) {
$shell->write(date(DATE_ATOM)."\n");
});