hphp/hack/manual/apis/Functions/HH.Asio/mmw.md
:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::
Returns an Awaitable of Map of ResultOrExceptionWrapper after a
mapping operation has been applied to each value in the provided
KeyedTraversable
namespace HH\Asio;
function mmw<Tk as arraykey, Tv, Tr>(
KeyedTraversable<Tk, Tv> $inputs,
(function(Tv): Awaitable<Tr>) $callable,
): Awaitable<Map<Tk, ResultOrExceptionWrapper<Tr>>>;
This function is similar to mm(), except the Map in the returned
Awaitable contains values of ResultOrExceptionWrapper instead of raw
values.
This function is similar to Map::map(), but the mapping of the values
is done using Awaitables.
This function is called mmw because we are returning a map, doing a
mapping operation and each value member in the Map is wrapped by a
ResultOrExceptionWrapper.
$callable must return an Awaitable.
The ResultOrExceptionWrappers in the Map of the returned Awaitable
are not available until you await or join the returned Awaitable.
KeyedTraversable<Tk,Tv> $inputs - The KeyedTraversable of values to map.(function(Tv): Awaitable<Tr>) $callable - The callable containing the Awaitable operation to
apply to $inputs.Awaitable<Map<Tk,ResultOrExceptionWrapper<Tr>>> - An Awaitable of Map of key/ResultOrExceptionWrapper pairs
after the mapping operation has been applied to the values in
$inputs.<<__EntryPoint>>
async function basic_usage_main(): Awaitable<void> {
// Map a map of numbers to their integer half
// throwing if they can't be divided evenly
$halves = await \HH\Asio\mmw(
Map {
'one' => 1,
'two' => 2,
'three' => 3,
'four' => 4,
},
async ($val) ==> {
if ($val % 2) {
throw new \Exception("$val is an odd number");
} else {
return $val / 2;
}
},
);
foreach ($halves as $num => $result) {
if ($result->isSucceeded()) {
echo "$num / two Success: ";
\var_dump($result->getResult());
} else {
echo "$num / two Failed: ";
\var_dump($result->getException()->getMessage());
}
}
}