reactphp-input-stream/examples/basic_example.php

18 lines
526 B
PHP
Raw Normal View History

2020-02-08 20:44:29 +01:00
<?php
use JoopSchilder\React\Stream\NonBlockingInput\ReadableNonBlockingInputStream;
use React\EventLoop\Factory;
require_once __DIR__ . '/../vendor/autoload.php';
2020-02-08 22:09:11 +01:00
require_once __DIR__ . '/demo_classes.php';
2020-02-08 20:44:29 +01:00
$input = new DemoNonBlockingInput();
$loop = Factory::create();
$stream = new ReadableNonBlockingInputStream($input, $loop);
$stream->on('data', fn() => print('m'));
$stream->on('error', fn() => print('e'));
$stream->on('close', fn() => print('c'));
$loop->addPeriodicTimer(0.2, fn() => print('.'));
$loop->run();