guzzle / promises

Promises/A+ library for PHP with synchronous support
MIT License
7.61k stars 116 forks source link

Persist order of keys for Utils::settle #139

Closed isaac-gilmour-asknicely closed 2 years ago

isaac-gilmour-asknicely commented 3 years ago

Description Currently, \GuzzleHttp\Promise\Utils::settle mangles the order of the responses returned. I propose the removal of ksort($results) to persist the order of the responses

Example

$client = new Client();
$promises = [
   'd' => $client->getAsync('https://example.com'),
   'c' => $client->getAsync('https://example.com'),
   'b' => $client->getAsync('https://example.com'),
   'a' => $client->getAsync('https://example.com'),
];

$responses = Utils::settle($promises)->wait();

foreach ($responses as $key => $result) {
  echo "$key\n";
}

Current output:

a
b
c
d

Expected output:

d
c
b
a
GrahamCampbell commented 2 years ago

This is intentional. They are yielded in the order they completed.