mpyw\Co\Co::start PHP Method

start() private method

Start resovling.
private start ( mixed $value, boolean $wait = true, mixed $throw = null )
$value mixed
$wait boolean
$throw mixed Used for Co::async() overrides.
    private function start($value, $wait = true, $throw = null)
    {
        $return = null;
        // For convenience, all values are wrapped into generator
        $con = YieldableUtils::normalize($this->getRootGenerator($throw, $value, $return));
        $promise = $this->processGeneratorContainerRunning($con);
        if ($promise instanceof ExtendedPromiseInterface) {
            // This is actually 100% true; just used for unwrapping Exception thrown.
            $promise->done();
        }
        // We have to wait $return only if $wait
        if ($wait) {
            $this->pool->wait();
            return $return;
        }
    }

Usage Example

Exemplo n.º 1
0
Arquivo: Co.php Projeto: mpyw/co
 /**
  * Value is recursively resolved, but we never wait it.
  * This function must be called along with Co::wait().
  * @param  mixed $value
  * @param  mixed $throw
  */
 public static function async($value, $throw = null)
 {
     if (!self::$self) {
         throw new \BadMethodCallException('Co::async() must be called along with Co::wait(). ');
     }
     if ($throw !== null) {
         $throw = filter_var($throw, FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]);
         if ($throw === null) {
             throw new \InvalidArgumentException("\$throw must be null or boolean.");
         }
     }
     self::$self->start($value, false, $throw);
 }