public function reject(Exception $exception): void
    {
        $this->exception = $exception;
        $this->state = Promise::REJECTED;

        while (count($this->onRejected) > 0) {
            $callback = array_shift($this->onRejected);
            try {
                $exception = call_user_func($callback, $this->exception);
                $this->exception = $exception;
            } catch (Exception $exception) {
                $this->exception = $exception;
            }
        }
    }