does the React\Promise\all returns the results in order? #538
Answered
by
clue
Amir-adibi
asked this question in
Q&A
|
Hello I have a question about the |
Answered by
clue
Oct 21, 2023
Replies: 1 comment
Yes, the <?php
require __DIR__ . '/vendor/autoload.php';
React\Promise\all([
'first' => new React\Promise\Promise(function (callable $resolve): void {
React\EventLoop\Loop::addTimer(0.2, fn() => $resolve(1));
}),
'second' => new React\Promise\Promise(function (callable $resolve): void {
React\EventLoop\Loop::addTimer(0.1, fn() => $resolve(2));
})
])->then(function (array $results): void {
var_dump($results);
});https://play.phpsandbox.io/react/async/R6NgB5WAVgpx98z0 I hope this helps! 👍 If so, consider supporting this project, for example by becoming a sponsor ❤️ |
0 replies
Answer selected by
Amir-adibi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, the
all()function is guaranteed to preserve the original array (or iterator) keys and their order.https://play.phpsandbox.io/re…