22declare(strict_types=1);
24namespace pocketmine\promise;
35 public function __construct(){
37 $this->promise =
new Promise($this->shared);
43 public function resolve(mixed $value) : void{
44 if($this->shared->state !== null){
45 throw new \LogicException(
"Promise has already been resolved/rejected");
47 $this->shared->state =
true;
48 $this->shared->result = $value;
49 foreach($this->shared->onSuccess as $c){
52 $this->shared->onSuccess = [];
53 $this->shared->onFailure = [];
56 public function reject() : void{
57 if($this->shared->state !== null){
58 throw new \LogicException(
"Promise has already been resolved/rejected");
60 $this->shared->state =
false;
61 foreach($this->shared->onFailure as $c){
64 $this->shared->onSuccess = [];
65 $this->shared->onFailure = [];
72 return $this->promise;