Asynchronous Operations: Concurrent

This functionality requires HHVM 4.6 or later.

concurrent concurrently awaits all awaits within a concurrent block and it works with await-as-an-expression as well!

Note: concurrent doesn't mean multithreading


concurrent {
  $x = await x_async();
  await void_async();
  $sum = await y_async() + await z_async()();
$y = $x + $sum;


Each of the statements in a concurrent block should be thought of as running concurrently. This means there shouldn't be any dependencies between the statements in a concurrent block.

Similar to await-as-an-expression, concurrent blocks don't provide a guaranteed order-of-execution between expressions being evaluated for any statement in the concurrent block. We guarantee that modifications to locals will happen after all other expressions resolve and will happen in the order in which they would happen outside a concurrent block.

For this example, we provide no guarantee on the order x(), y_async() or z_async() will be executed, but the assignments into $result are guaranteed to be well ordered.

$result = vec[];
concurrent {
  $result[] = x() + await y_async();
  $result[] = await z_async();