Ejemplo n.º 1
0
 public function __construct($taskId, Generator $coroutine)
 {
     $this->taskId = $taskId;
     $this->coroutine = stackedCoroutine($coroutine);
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider testThrowProvider
  */
 public function testThrow($coroutineFactory, $throwAtKeys, $expectedArray, $shouldThrow)
 {
     $coroutine = stackedCoroutine($coroutineFactory());
     $throwAtKeys = array_flip($throwAtKeys);
     $hasThrown = false;
     $resultArray = [];
     try {
         foreach ($coroutine as $key => $value) {
             $resultArray[] = $value;
             if (isset($throwAtKeys[$key])) {
                 $resultArray[] = $coroutine->throw(new \Exception());
             }
         }
     } catch (\Exception $e) {
         $hasThrown = true;
     }
     if ($shouldThrow !== $hasThrown) {
         $this->fail('Throwiness does not match');
     }
     $this->assertEquals($expectedArray, $resultArray);
 }