You are here

public function FunctionsTest::testCanNestYieldsAndFailures in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/guzzlehttp/promises/tests/functionsTest.php \GuzzleHttp\Promise\Tests\FunctionsTest::testCanNestYieldsAndFailures()

File

vendor/guzzlehttp/promises/tests/functionsTest.php, line 562

Class

FunctionsTest

Namespace

GuzzleHttp\Promise\Tests

Code

public function testCanNestYieldsAndFailures() {
  $p1 = new P\Promise();
  $p2 = new P\Promise();
  $p3 = new P\Promise();
  $p4 = new P\Promise();
  $p5 = new P\Promise();
  $co = P\coroutine(function () use ($p1, $p2, $p3, $p4, $p5) {
    try {
      (yield $p1);
    } catch (\Exception $e) {
      (yield $p2);
      try {
        (yield $p3);
        (yield $p4);
      } catch (\Exception $e) {
        (yield $p5);
      }
    }
  });
  $p1
    ->reject('a');
  $p2
    ->resolve('b');
  $p3
    ->resolve('c');
  $p4
    ->reject('d');
  $p5
    ->resolve('e');
  $co
    ->then(function ($value) use (&$result) {
    $result = $value;
  });
  P\queue()
    ->run();
  $this
    ->assertEquals('e', $result);
}