result !== null){ $callback($this); }else{ $this->callbacks[] = $callback; } } public function resolve(string $result) : void{ if($this->result !== null){ throw new \InvalidStateException("Cannot resolve promise more than once"); } $this->result = $result; foreach($this->callbacks as $callback){ $callback($this); } $this->callbacks = []; } public function getResult() : string{ if($this->result === null){ throw new \InvalidStateException("Promise has not yet been resolved"); } return $this->result; } public function hasResult() : bool{ return $this->result !== null; } }