result = $result; $this->error = $e; } /** * @return mixed */ public function wait() { if ($this->error) { throw $this->error; } return $this->result; } public function cancel() {} /** * @return PromiseInterface */ public function promise() { if (!$this->cachedPromise) { $this->cachedPromise = $this->error ? new RejectedPromise($this->error) : new FulfilledPromise($this->result); } return $this->cachedPromise; } /** * @return PromiseInterface */ public function then( callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null ) { return $this->promise()->then($onFulfilled, $onRejected, $onProgress); } }