2020-12-11 01:25:38 +01:00
|
|
|
<?php
|
|
|
|
|
2020-12-12 13:05:48 +01:00
|
|
|
use React\EventLoop\Factory;
|
|
|
|
use Toalett\Multiprocessing\Concurrency;
|
2020-12-11 01:25:38 +01:00
|
|
|
use Toalett\Multiprocessing\ContextBuilder;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
|
2020-12-12 13:05:48 +01:00
|
|
|
$loop = Factory::create();
|
2020-12-12 02:11:05 +01:00
|
|
|
$context = ContextBuilder::create()
|
2020-12-12 13:05:48 +01:00
|
|
|
->withEventLoop($loop)
|
|
|
|
->withConcurrency(Concurrency::atMost(4))
|
|
|
|
->build();
|
2020-12-11 01:25:38 +01:00
|
|
|
|
|
|
|
$context->on('booted', fn() => print("🚽 Toalett Multiprocessing Context\n"));
|
|
|
|
$context->on('congestion', fn() => print('C'));
|
|
|
|
$context->on('congestion_relieved', fn() => print('R'));
|
|
|
|
$context->on('worker_started', fn() => print('+'));
|
|
|
|
$context->on('worker_stopped', fn() => print('-'));
|
|
|
|
|
|
|
|
$loop->addPeriodicTimer(1, fn() => $context->submit(fn(int $s) => sleep($s), random_int(0, 10)));
|
|
|
|
|
|
|
|
print("Press CTRL+C to stop.\n");
|
|
|
|
$context->run();
|