本文整理匯總了PHP中State::PENDING方法的典型用法代碼示例。如果您正苦於以下問題:PHP State::PENDING方法的具體用法?PHP State::PENDING怎麽用?PHP State::PENDING使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類State
的用法示例。
在下文中一共展示了State::PENDING方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: cancel
/**
* @return bool
*/
public function cancel()
{
if ($this->promise()->state()->equals(State::PENDING())) {
$this->reject(new CancellationException());
return true;
}
return false;
}
示例2: changeState
/**
* @param mixed $result
* @param bool $success
*
* @throws \LogicException
*/
private function changeState($result, $success)
{
if ($this->state()->equals(State::PENDING())) {
$this->actual = $success ? new FulfilledPromise($result) : new RejectedPromise($result);
while (!empty($this->resolvers)) {
/** @var \Cubiche\Core\Async\Promise\ResolverInterface $resolver */
$resolver = array_shift($this->resolvers);
if ($success) {
$resolver->resolve($result);
} else {
$resolver->reject($result);
}
}
} else {
throw new \LogicException(\sprintf('A %s promise cannot be %s', $this->state(), $success ? 'resolved' : 'rejected'));
}
}