getYieldables() public static méthode

Each entries are assoc those contain keys 'value' and 'keylist'. value -> the value itself. keylist -> position of the value. nests are represented as array values.
public static getYieldables ( mixed $value, array $keylist = [], array &$runners = [] ) : array
$value mixed Must be already normalized.
$keylist array Internally used.
$runners array
Résultat array
Exemple #1
0
 /**
  * Executed by Co::any() or Co::race().
  * @param  mixed    $value
  * @param  callable $filter  self::reverse or self::fail.
  * @param  string   $message Used for failure.
  * @return \Generator
  */
 public static function anyOrRace($value, callable $filter, $message)
 {
     $value = YieldableUtils::normalize($value);
     $yieldables = YieldableUtils::getYieldables($value);
     $wrapper = self::getWrapperGenerator($yieldables, $filter);
     try {
         $results = (yield $wrapper);
     } catch (ControlException $e) {
         (yield CoInterface::RETURN_WITH => $e->getValue());
     }
     $apply = YieldableUtils::getApplier($value, $yieldables);
     throw new AllFailedException($message, 0, $apply($results));
 }
Exemple #2
0
Fichier : Co.php Projet : mpyw/co
 /**
  * Handle resolving generators still running.
  * @param  GeneratorContainer $gc
  * @return PromiseInterface
  */
 private function processGeneratorContainerRunning(GeneratorContainer $gc)
 {
     // Check delay request yields
     if ($gc->key() === CoInterface::DELAY) {
         return $this->pool->addDelay($gc->current())->then(function () use($gc) {
             $gc->send(null);
             return $this->processGeneratorContainer($gc);
         });
     }
     // Now we normalize yielded value
     $yielded = YieldableUtils::normalize($gc->current());
     $yieldables = YieldableUtils::getYieldables($yielded, [], $this->runners);
     if (!$yieldables) {
         // If there are no yieldables, send yielded value back into generator
         $gc->send($yielded);
         // Continue
         return $this->processGeneratorContainer($gc);
     }
     // Chain resolver
     return $this->promiseAll($yieldables, $gc->key() !== CoInterface::SAFE)->then(YieldableUtils::getApplier($yielded, $yieldables, [$gc, 'send']), [$gc, 'throw_'])->then(function () use($gc, $yieldables) {
         // Continue
         $this->runners = array_diff_key($this->runners, $yieldables);
         return $this->processGeneratorContainer($gc);
     });
 }
Exemple #3
0
 public function testGetYieldables()
 {
     $genfunc = function () {
         (yield null);
     };
     $r = ['x' => ['y1' => (object) ['ignored_0' => curl_init(), 'ignored_1' => new GeneratorContainer($genfunc())], 'y2' => ['z1' => $z1 = curl_init(), 'z2' => $z2 = new GeneratorContainer($genfunc())]]];
     $this->assertEquals([(string) $z1 => ['value' => $z1, 'keylist' => ['x', 'y2', 'z1']], (string) $z2 => ['value' => $z2, 'keylist' => ['x', 'y2', 'z2']]], YieldableUtils::getYieldables($r));
 }