<?php
use parallel\{Events, Events\Event, Runtime};
$events = new Events();
$runtime = new Runtime();
$future = $runtime->run(
static function (string $name) {
return "Future#$name result";
},
['Read']
);
$events->addFuture("Future#Read", $future);
$future = $runtime->run(
static function (string $name) {
throw new \Exception("Exception#$name");
},
['Cancel']
);
$events->addFuture("Future#Cancel", $future);
$future = $runtime->run(
static function () {
sleep(100000);
},
[]
);
$events->addFuture("Future#Kill", $future);
$future->cancel(); $future = $runtime->run(
static function () {
$memoryEater = [];
$i = 0;
while (++$i) {
$memoryEater[] = $i;
}
}
);
$events->addFuture("Future#Error", $future);
foreach ($events as $i => $event) {
echo str_pad('', 50, '=') . " EVENT_$i\n";
var_dump($event);
echo "\n";
}