Ohad Koren
Ohad Koren

Reputation: 121

waiting for all promises to finish in react PHP

I have an array of promises.

I want to proceed only after all of the promises gave me a response no matter if they were resolved or reject. I thought that all() function can handle it, but it looks like it works only when all of the promises in the array are resolved and without considering rejections for some of the promises.

What function can I use??

example: the function getUser returns a promise object. When all of the promises gave me a response, i would like to catch the trigger, whether the promise is resolved or rejected.

array_push($this->users['users'], $this->userFetcher->getUser($userName));

Thanks :)

Upvotes: 5

Views: 4202

Answers (1)

Benjamin Gruenbaum
Benjamin Gruenbaum

Reputation: 276326

Use all():

$getAllUsers = React\Promise\all($this->users['users']);
$getAllUsers->then(function ($users) { 
   echo "Got all users" . $users;
});

Upvotes: 3

Related Questions