Skip to content

Instantly share code, notes, and snippets.

@proudlygeek
Forked from cburgdorf/gist:9713936
Created March 24, 2014 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proudlygeek/9738711 to your computer and use it in GitHub Desktop.
Save proudlygeek/9738711 to your computer and use it in GitHub Desktop.
<?hh
async function helloAfter($name, $timeout) {
// sleep asynchronously -- let other async functions do their job
await SleepWaitHandle::create($timeout * 1000000);
echo sprintf("hello %s\n", $name);
}
async function run() {
$joe = helloAfter('Joe', 3);
$mike = helloAfter('Mike', 1);
// wait for both dependencies
await GenArrayWaitHandle::create(array($joe, $mike));
}
run()->join();
// prints:
// hello Mike
// hello Joe
//The example is based on the discussion provided here: https://github.com/facebook/hhvm/issues/1494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment