44 public function onCompletion(\Closure $onSuccess, \Closure $onFailure) : void{
45 $state = $this->shared->state;
47 $onSuccess($this->shared->result);
48 }elseif($state ===
false){
51 $this->shared->onSuccess[spl_object_id($onSuccess)] = $onSuccess;
52 $this->shared->onFailure[spl_object_id($onFailure)] = $onFailure;
77 if(count($promises) === 0){
78 throw new \InvalidArgumentException(
"At least one promise must be provided");
83 $toResolve = count($promises);
86 foreach($promises as $key => $promise){
87 $promise->onCompletion(
88 function(mixed $value) use ($resolver, $key, $toResolve, &$values) :
void{
89 $values[$key] = $value;
91 if(count($values) === $toResolve){
92 $resolver->resolve($values);
95 function() use ($resolver, &$continue) : void{
108 return $resolver->getPromise();