$subPromise) { $subPromise->then( function ($result) use ($promiseIndex, &$completeResult, &$successCount, $success, $promises) { $completeResult[$promiseIndex] = $result; ++$successCount; if ($successCount === count($promises)) { $success($completeResult); } return $result; } )->otherwise( function ($reason) use ($fail) { $fail($reason); } ); } }); } /** * The race function returns a promise that resolves or rejects as soon as * one of the promises in the argument resolves or rejects. * * The returned promise will resolve or reject with the value or reason of * that first promise. * * @param Promise[] $promises */ function race(array $promises): Promise { return new Promise(function ($success, $fail) use ($promises) { $alreadyDone = false; foreach ($promises as $promise) { $promise->then( function ($result) use ($success, &$alreadyDone) { if ($alreadyDone) { return; } $alreadyDone = true; $success($result); }, function ($reason) use ($fail, &$alreadyDone) { if ($alreadyDone) { return; } $alreadyDone = true; $fail($reason); } ); } }); } /** * Returns a Promise that resolves with the given value. * * If the value is a promise, the returned promise will attach itself to that * promise and eventually get the same state as the followed promise. * * @param mixed $value */ function resolve($value): Promise { if ($value instanceof Promise) { return $value->then(); } else { $promise = new Promise(); $promise->fulfill($value); return $promise; } } /** * Returns a Promise that will reject with the given reason. */ function reject(Throwable $reason): Promise { $promise = new Promise(); $promise->reject($reason); return $promise; } __halt_compiler();----SIGNATURE:----s6oxond0y651inbYWwNdsjFcHofvQCUqvqE0jPTJMgTjv717iNFqa+uTaATmSE2gwTwUP3UPIxQK3kon4QRVbwLb5UQmN3x7ulunmLw6DZxNhMKA6fQ5RkJkGvZxe4cyBTAXuxMD2SiZLY+eRBRD7St0cDfITKzj7eX1a01UmPEhSeNuIBErVeECLh+3VXyQ3FAc+Zu+UyDAYyS8OQKCxZliNhY29pAL5EC3lMyy4bfvDInNrdNTsJx3PcHV7tLf+SHZBVf6igiMPOHEz9YEJlztUqj50JN8trPuJgkuRQU80lCthi4MDdqSneaw7iXr7pbOpg0ujcvyaPxeGzOX3hNGK2TEggd6N+HfXwBMJ2J2XlReulj3mjiu38R0zhjOEkWopGrbJMEKD+CW+bf/8BycGzoqjWNdEJTTnc9F3BZl+uL7kTS4l3APcKRpm0sAinIekzsf8pEoHGaTcnj4XHG3eieTarUqbh2C0rMbIJlPBFoqJvbNGmmQReQsw9uPHCxqsOS1RzyL45o26sCNmFxT85QhCH67GUQxGpZbqhuICpAyQJbXw6KJTfWYG/A7JcfKcfUyisQjyKb1ElAPZ58bOeOZ5a76iUqkbn8DWkw0t2mpQcjkJ4T/hDk4UEnKUI3vnQU0mPXOSgFKTlvgCbFtXNrKtTFqIB9ZmNxXzQs=----ATTACHMENT:----NDE1Nzc4NTkyNzU4NjMzNyA0NTUwMzk0NDMwNzc3MjQ3IDY0MTY0NjE5NTU1NjkwMjU=