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;
}
}
/** * 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); }