note 124208 added to class.parallel-channel
| From: | rustysun@php.net | Date: | Wed, 18 Sep 2019 22:28:28 +0000 |
| Subject: | note 124208 added to class.parallel-channel | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-212247@lists.php.net to get a copy of this message | ||
an example used unbuffered channel.
<?php
use parallel\{Channel,Runtime};
$sum=function(array $a, Channel $ch) {
$sum=0;
foreach ($a as $v) {
$sum+=$v;
}
$ch->send($sum);
};
try {
$a=[7, 2, 8, 1, 4, 0, 9, 10];
//unbuffered channel
$runtime=new Runtime;
$ch2=new Channel;
$runtime->run($sum, [array_slice($a, 0, $num), $ch2]);
$runtime->run($sum, [array_slice($a, $num), $ch2]);
//receive from channel
$x=$ch2->recv();
$y=$ch2->recv();
$ch2->close();
echo "\nch2:", $x, "\t", $y, "\t", $x + $y, "\n";
} catch(Error $err) {
echo "\nError:", $err->getMessage();
} catch(Exception $e) {
echo "\nException:", $e->getMessage();
}
//output
//ch2:18 23 41
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.168 (proxied: 115.193.204.243)
----
Manual Page -- http://php.net/manual/en/class.parallel-channel.php
Edit -- https://master.php.net/note/edit/124208
Del: integrated -- https://master.php.net/note/delete/124208/integrated
Del: useless -- https://master.php.net/note/delete/124208/useless
Del: bad code -- https://master.php.net/note/delete/124208/bad+code
Del: spam -- https://master.php.net/note/delete/124208/spam
Del: non-english -- https://master.php.net/note/delete/124208/non-english
Del: in docs -- https://master.php.net/note/delete/124208/in+docs
Del: other reasons-- https://master.php.net/note/delete/124208
Reject -- https://master.php.net/note/reject/124208
Search -- https://master.php.net/manage/user-notes.php