<?php require_once "../vendor/autoload.php"; use Hprose\Future; $p = Future\reject(new OutOfRangeException()); $p->catchError(function ($reason) { return 'this is a OverflowException'; }, function ($reason) { return $reason instanceof OverflowException; })->catchError(function ($reason) { return 'this is a OutOfRangeException'; }, function ($reason) { return $reason instanceof OutOfRangeException; })->then(function ($value) { var_dump($value); });
<?php require_once "../vendor/autoload.php"; use Hprose\Future; $p1 = Future\resolve('resolve hprose'); $p1->whenComplete(function () { var_dump('p1 complete'); })->then(function ($value) { var_dump($value); }); $p2 = Future\reject(new Exception('reject thrift')); $p2->whenComplete(function () { var_dump('p2 complete'); })->catchError(function ($reason) { var_dump($reason->getMessage()); }); $p3 = Future\resolve('resolve protobuf'); $p3->whenComplete(function () { var_dump('p3 complete'); throw new Exception('reject protobuf'); })->catchError(function ($reason) { var_dump($reason->getMessage()); });
<?php require_once "../vendor/autoload.php"; use Hprose\Future; $p1 = Future\resolve(3); $p2 = Future\reject(new Exception("x")); Future\settle(array(true, $p1, $p2))->then('print_r');