private function settle(ExtendedPromiseInterface $result)
{
if ($result instanceof LazyPromise) {
$result = $result->promise();
}
if ($result === $this) {
$result = new RejectedPromise(new \LogicException('Cannot resolve a promise with itself.'));
}
$handlers = $this->handlers;
$this->handlers = [];
$this->result = $result;
foreach ($handlers as $handler) {
$handler($result);
}
}