HH\Asio\mw
Translate a KeyedTraversable
of Awaitables
into a single Awaitable
of
Map
of key/ResultOrExceptionWrapper
pairs
namespace HH\Asio;
function mw<Tk as arraykey, Tv>(
KeyedTraversable<Tk, Awaitable<Tv>> $awaitables,
): Awaitable<Map<Tk, ResultOrExceptionWrapper<Tv>>>;
This function is the same as m()
, but wraps the results into
key/ResultOrExceptionWrapper
pairs.
This function takes any KeyedTraversable
object of Awaitables
(i.e., each
member of the KeyedTraversable
has a value of type Awaitable
, likely
from a call to a function that returned Awaitable<T>
), and transforms those
Awaitables
into one big Awaitable
Map
of
key/ResultOrExceptionWrapper
pairs.
This function is called mw
because we are returning a m
ap of
Awaitable
w
rapped into ResultofExceptionWrapper
s.
The ResultOrExceptionWrapper
values in the Map
of the returned
Awaitable
are not available until you await
or join
the returned
Awaitable
.
Parameters
KeyedTraversable<Tk,
Awaitable<Tv>> $awaitables
- The collection ofKeyedTraversable
awaitables.
Returns
Awaitable<Map<Tk,
ResultOrExceptionWrapper<Tv>>>
- AnAwaitable
ofMap
of key/ResultOrExceptionWrapper
pairs, where theMap
was generated from eachKeyedTraversable
member in$awaitables
.
Examples
async function one(): Awaitable<int> {
return 1;
}
<<__EntryPoint>>
async function basic_usage_main(): Awaitable<void> {
$mcr = \MCRouter::createSimple(ImmVector {});
$handles = \HH\Asio\mw(Map {
// This will throw an exception, since there's no servers to speak to
'cache' => $mcr->get("no-such-key"),
// While this will obviously succeed
'one' => one(),
});
$results = await $handles;
foreach ($results as $key => $result) {
if ($result->isSucceeded()) {
echo "$key Success: ";
\var_dump($result->getResult());
} else {
echo "$key Failed: ";
\var_dump($result->getException()->getMessage());
}
}
}
```.skipif
\Hack\UserDocumentation\API\Examples\MCRouter\skipif();