Esempio n. 1
0
 public function testIsGeneratorContainer()
 {
     $gen = (function () {
         (yield 1);
     })();
     $con = new GeneratorContainer($gen);
     $this->assertTrue(TypeUtils::isGeneratorContainer($con));
     $this->assertFalse(TypeUtils::isGeneratorContainer($gen));
 }
Esempio n. 2
0
 /**
  * Return Promise that absorbs rejects, excluding fatal Throwable.
  * @param  PromiseInterface $promise
  * @return PromiseInterface
  */
 public static function safePromise(PromiseInterface $promise)
 {
     return $promise->then(null, function ($value) {
         if (TypeUtils::isFatalThrowable($value)) {
             throw $value;
         }
         return $value;
     });
 }
Esempio n. 3
0
File: Co.php Progetto: mpyw/co
 /**
  * Promise all changes in yieldables are prepared.
  * @param  array $yieldables
  * @param  bool  $throw_acceptable
  * @return PromiseInterface
  */
 private function promiseAll(array $yieldables, $throw_acceptable)
 {
     $promises = [];
     foreach ($yieldables as $yieldable) {
         // Add or enqueue cURL handles
         if (TypeUtils::isCurl($yieldable['value'])) {
             $promises[(string) $yieldable['value']] = $this->pool->addCurl($yieldable['value']);
             continue;
         }
         // Process generators
         if (TypeUtils::isGeneratorContainer($yieldable['value'])) {
             $promises[(string) $yieldable['value']] = $this->processGeneratorContainer($yieldable['value']);
             continue;
         }
     }
     // If caller cannot accept exception,
     // we handle rejected value as resolved.
     if (!$throw_acceptable) {
         $promises = array_map(['\\mpyw\\Co\\Internal\\YieldableUtils', 'safePromise'], $promises);
     }
     return \React\Promise\all($promises);
 }