note 126416 added to class.parallel-events
| From: | gam6itko at main dot php dot net | Date: | Sat, 11 Sep 2021 15:28:38 +0000 |
| Subject: | note 126416 added to class.parallel-events | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216948@lists.php.net to get a copy of this message | ||
<?php
// this example shows how Events handle Future events
use parallel\{Events, Events\Event, Runtime};
$events = new Events();
$runtime = new Runtime();
//Read (type: 1)
$future = $runtime->run(
static function (string $name) {
return "Future#$name result";
},
['Read']
);
$events->addFuture("Future#Read", $future);
//Cancel (type: 4)
$future = $runtime->run(
static function (string $name) {
throw new \Exception("Exception#$name");
},
['Cancel']
);
$events->addFuture("Future#Cancel", $future);
//Kill (type: 5)
$future = $runtime->run(
static function () {
sleep(100000);
},
[]
);
$events->addFuture("Future#Kill", $future);
$future->cancel(); //kill it
//Error (type: 6)
$future = $runtime->run(
static function () {
$memoryEater = [];
$i = 0;
while (++$i) {
$memoryEater[] = $i;
}
}
);
$events->addFuture("Future#Error", $future);
// reading events
/** @var Event $event */
foreach ($events as $i => $event) {
echo str_pad('', 50, '=') . " EVENT_$i\n";
var_dump($event);
echo "\n";
}
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 176.104.221.149)
----
Manual Page -- https://php.net/manual/en/class.parallel-events.php
Edit -- https://main.php.net/note/edit/126416
Del: integrated -- https://main.php.net/note/delete/126416/integrated
Del: useless -- https://main.php.net/note/delete/126416/useless
Del: bad code -- https://main.php.net/note/delete/126416/bad+code
Del: spam -- https://main.php.net/note/delete/126416/spam
Del: non-english -- https://main.php.net/note/delete/126416/non-english
Del: in docs -- https://main.php.net/note/delete/126416/in+docs
Del: other reasons-- https://main.php.net/note/delete/126416
Reject -- https://main.php.net/note/reject/126416
Search -- https://main.php.net/manage/user-notes.php