在react PHP中等待所有承诺完成


waiting for all promises to finish in react PHP

我有一个承诺数组

我想只有在所有的承诺给我一个回应之后,不管他们是解决了还是拒绝了。我认为all()函数可以处理它,但它看起来只有在数组中的所有承诺都被解决并且不考虑拒绝某些承诺时才有效。

我可以使用什么函数??

示例:getUser函数返回一个promise对象。当所有的承诺给我一个响应,我想抓住触发器,无论承诺是解决还是拒绝。

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

谢谢:)

使用all():

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