Created
May 28, 2014 10:51
-
-
Save brianium/ff20fe672939de8865fa to your computer and use it in GitHub Desktop.
async hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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