*/ private PromiseSharedData $shared; /** @phpstan-var Promise */ private Promise $promise; public function __construct(){ $this->shared = new PromiseSharedData(); $this->promise = new Promise($this->shared); } /** * @phpstan-param TValue $value */ public function resolve(mixed $value) : void{ if($this->shared->resolved){ throw new \LogicException("Promise has already been resolved/rejected"); } $this->shared->resolved = true; $this->shared->result = $value; foreach($this->shared->onSuccess as $c){ $c($value); } $this->shared->onSuccess = []; $this->shared->onFailure = []; } public function reject() : void{ if($this->shared->resolved){ throw new \LogicException("Promise has already been resolved/rejected"); } $this->shared->resolved = true; foreach($this->shared->onFailure as $c){ $c(); } $this->shared->onSuccess = []; $this->shared->onFailure = []; } /** * @phpstan-return Promise */ public function getPromise() : Promise{ return $this->promise; } }