Simplified codebase in a major refactor before moving to initial Toalett release
This commit is contained in:
25
examples/exception_after_4_seconds.php
Normal file
25
examples/exception_after_4_seconds.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use React\EventLoop\Factory;
|
||||
use Toalett\React\Stream\StreamAdapter;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/classes.php';
|
||||
|
||||
$loop = Factory::create();
|
||||
$loop->addPeriodicTimer(0.2, fn() => print('.'));
|
||||
|
||||
$stream = new StreamAdapter(new WillThrowExceptionAfter4Seconds(), $loop);
|
||||
$stream->on('data', fn() => print('Data received.' . PHP_EOL));
|
||||
$stream->on('error', fn(Throwable $t) => print('Error: ' . $t->getMessage() . PHP_EOL));
|
||||
$stream->on('close', fn() => print('Stream closed.' . PHP_EOL));
|
||||
|
||||
print(<<<EOF
|
||||
This program demonstrates an example of a source that fails after 4 seconds.
|
||||
Press CTRL+C to stop.
|
||||
|
||||
|
||||
EOF
|
||||
);
|
||||
|
||||
$loop->run();
|
||||
Reference in New Issue
Block a user