function hello($n, $test) { $result = array(); for ($i = 0; $i < 5; $i++) { $result[] = $test->hello("{$n}-{$i}"); } (yield Future\all($result)); }
<?php require_once "../vendor/autoload.php"; use Hprose\Future; use Hprose\Swoole\Client; Future\co(function () { $test = new Client("tcp://127.0.0.1:1314"); $test->fullDuplex = true; $start = microtime(true); $n = 100; $m = 100; for ($j = 0; $j < $n; $j++) { $results = array(); for ($i = 0; $i < $m; $i++) { $results[] = $test->hello("{$j}-{$i}"); } (yield Future\all($results)); } $total = microtime(true) - $start; $average = $total / $n / $m; var_dump($total); var_dump($average); });
function all($array) { return Future\all($array); }
<?php require_once "../vendor/autoload.php"; use Hprose\Future; Future\all(array(1, Future\value(2), 3))->then(function ($value) { var_dump($value); }); Future\join(1, Future\value(2), 3)->then(function ($value) { var_dump($value); });