Returns an Awaitable of Map containing after a mapping operation has been applied to each value in the provided KeyedTraversable


function mm<Tk, Tv, Tr>(
  KeyedTraversable<Tk, Tv> $inputs,
  (function(Tv):Awaitable<Tr>) $callable,
): Awaitable<Map<Tk, Tr>>

This function is similar to Map::map(), but the mapping of the values is done using Awaitables.

This function is called mm because we are returning a map, and doing a mapping operation.

$callable must return an Awaitable.

The keys and values in the Map of the returned Awaitable are not available until you await or join the returned Awaitable.


  • $inputs - The KeyedTraversable of values to map.
  • $callable - The callable containing the Awaitable operation to apply to $inputs.

Return Values



namespace Hack\UserDocumentation\API\Examples\HH\Asio\mm;

 * Query an arbitrary number of URLs in parallel
 * returning them as a Map of string responses.
 * Refer to \HH\Asio\m() for a more verbose version of this.
async function get_urls(
  \ConstMap<string, string> $urls,
): Awaitable<Map<string, string>> {

  // Invoke \HH\Asio\curl_exec for each URL,
  // then await on each in parallel
  return await \HH\Asio\mm(

$urls = ImmMap {
  'com' => "http://example.com",
  'net' => "http://example.net",
  'org' => "http://example.org",

$pages = \HH\Asio\join(get_urls($urls));
foreach ($pages as $name => $page) {
  echo $name, ': ';
  echo substr($page, 0, 15) . ' ... ' . substr($page, -8);
com: <!doctype html> ... </html>
net: <!doctype html> ... </html>
org: <!doctype html> ... </html>