Skip to content

Instantly share code, notes, and snippets.

@brianium
Created May 28, 2014 10:51
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 brianium/ff20fe672939de8865fa to your computer and use it in GitHub Desktop.
Save brianium/ff20fe672939de8865fa to your computer and use it in GitHub Desktop.
async hack
<?hh
type SomeResult = shape('property' => int);
function doIoBoundThing(): void {
$nums = array(
100000000,
1000000000,
);
foreach ($nums as $num) {
$i = 0;
while(++$i < $num) {
//such iteration
}
}
return shape('property' => 100000);
}
async function async_io(): Awaitable<int> {
print "Starting IO bound thing\n";
$result = doIoBoundThing();
await RescheduleWaitHandle::create(1,1);
print "Returning IO result\n";
return $result['property'];
}
async function async_main(): Awaitable<void> {
$handles = [];
for ($i = 0; $i < 5; $i++) {
$handles[] = async_io();
}
$x = await GenArrayWaitHandle::create($handles);
print count($x);
print "\n\n";
}
async_main()->join();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment