mpyw\Co\Internal\ControlUtils::anyOrRace PHP Method

anyOrRace() public static method

Executed by Co::any() or Co::race().
public static anyOrRace ( mixed $value, callable $filter, string $message ) : Generator
$value mixed
$filter callable self::reverse or self::fail.
$message string 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));
    }

Usage Example

示例#1
0
文件: Co.php 项目: mpyw/co
 /**
  * Wrap value with the Generator that returns the first result.
  * If no yieldables found, AllFailedException is thrown.
  *
  * @param  mixed $value
  * @return \Generator Resolved value.
  * @throws \RuntimeException|AllFailedException
  */
 public static function race($value)
 {
     (yield Co::RETURN_WITH => (yield ControlUtils::anyOrRace($value, ['\\mpyw\\Co\\Internal\\ControlUtils', 'fail'], 'Co::race() failed.')));
     // @codeCoverageIgnoreStart
 }