| 1 |
<<__EntryPoint>> |
| 2 |
async function my_example(): Awaitable<void> { |
| 3 |
$user_ids = vec[1, 2, 3]; |
| 4 |
|
| 5 |
// Initiate all the database requests together, |
| 6 |
// so we spend less time waiting. |
| 7 |
$user_names = await Vec\map_async( |
| 8 |
$user_ids, |
| 9 |
async ($id) ==> await fetch_user_name($id), |
| 10 |
); |
| 11 |
// Execution continues after requests complete. |
| 12 |
|
| 13 |
echo Str\join($user_names, ", "); |
| 14 |
} |
| 15 |
|
| 16 |
async function fetch_user_name( |
| 17 |
int $_, |
| 18 |
): Awaitable<string> { |
| 19 |
// This could be a database request. |
| 20 |
return ""; |
| 21 |
} |
| 22 |
|
| 23 |
// From hacklang.org |
| 24 |
|