mpyw\Co\Internal\YieldableUtils::getApplier PHP Method

getApplier() public static method

Return function that apply changes in yieldables.
public static getApplier ( mixed $yielded, array $yieldables, callable $next = null ) : mixed
$yielded mixed
$yieldables array
$next callable
return mixed
    public static function getApplier($yielded, array $yieldables, callable $next = null)
    {
        return function (array $results) use($yielded, $yieldables, $next) {
            foreach ($results as $hash => $resolved) {
                $current =& $yielded;
                foreach ($yieldables[$hash]['keylist'] as $key) {
                    $current =& $current[$key];
                }
                $current = $resolved;
                unset($current);
            }
            return $next ? $next($yielded) : $yielded;
        };
    }

Usage Example

Exemplo n.º 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));
 }
All Usage Examples Of mpyw\Co\Internal\YieldableUtils::getApplier