Example #1
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
$dump = Future\wrap('var_dump');
function isBigEnough($value)
{
    return $value >= 10;
}
$a1 = Future\value(array(12, Future\value(5), 8, Future\value(130), 44));
$a2 = Future\value(array(12, Future\value(54), 18, Future\value(130), 44));
$dump($a1->every('isBigEnough'));
// false
$dump($a2->every('isBigEnough'));
// true
Example #2
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
use Hprose\Swoole\Client;
$test = new Client("unix:/tmp/my.sock");
$var_dump = Future\wrap("var_dump");
Future\co(function () use($test) {
    try {
        var_dump((yield $test->hello("yield world1")));
        var_dump((yield $test->hello("yield world2")));
        var_dump((yield $test->hello("yield world3")));
        var_dump((yield $test->hello("yield world4")));
        var_dump((yield $test->hello("yield world5")));
        var_dump((yield $test->hello("yield world6")));
    } catch (\Exception $e) {
        echo $e;
    }
});
$var_dump($test->hello("async world1"));
$var_dump($test->hello("async world2"));
$var_dump($test->hello("async world3"));
$var_dump($test->hello("async world4"));
$var_dump($test->hello("async world5"));
$var_dump($test->hello("async world6"));
$test->hello("world1")->then(function ($result) use($test) {
    var_dump($result);
    return $test->hello("world2");
})->then(function ($result) use($test) {
    var_dump($result);
    return $test->hello("world3");
Example #3
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
class Test
{
    function add($a, $b)
    {
        return $a + $b;
    }
    function sub($a, $b)
    {
        return $a - $b;
    }
    function mul($a, $b)
    {
        return $a * $b;
    }
    function div($a, $b)
    {
        return $a / $b;
    }
}
$var_dump = Future\wrap('var_dump');
$test = Future\wrap(new Test());
$var_dump($test->add(1, Future\value(2)));
$var_dump($test->sub(Future\value(1), 2));
$var_dump($test->mul(Future\value(1), Future\value(2)));
$var_dump($test->div(1, 2));
Example #4
0
function wrap($handler)
{
    return Future\wrap($handler);
}
Example #5
0
<?php

require_once "../vendor/autoload.php";
use Hprose\Future;
use Hprose\Http\Client;
$test = new Client("http://hprose.com/example/");
$coroutine = Future\wrap(function ($test) {
    var_dump(1);
    var_dump((yield $test->hello("hprose")));
    $a = $test->sum(1, 2, 3);
    $b = $test->sum(4, 5, 6);
    $c = $test->sum(7, 8, 9);
    var_dump((yield $test->sum($a, $b, $c)));
    var_dump((yield $test->hello("world")));
});
$coroutine($test);
$coroutine(Future\value($test));