protected function resolve($value = null)
    {
        if (null !== $this->result) {
            return;
        }

        if ($value instanceof self) {
            $value = $value->unwrap();
            if ($this === $value) {
                $value = new Internal\RejectedAwaitable(
                    new CircularResolutionError('Circular reference in awaitable resolution chain.')
                );
            }
        } elseif (!$value instanceof Awaitable) {
            $value = new Internal\FulfilledAwaitable($value);
        }

        $this->result = $value;
        $this->result->done($this->onFulfilled, $this->onRejected ?: new DoneQueue());

        $this->onFulfilled = null;
        $this->onRejected = null;
        $this->onCancelled = null;
    }