Re:Hack: a new programming language for HHVM
by elgenie on Thursday March 20, 2014 @02:54PM
(#7437777)
async/await allows cooperative multitasking on a single thread: stay tuned for more...
The way it works is quite different from your example:
async function gen_foo(): Awaitable<string> {
echo "until we get to an await, eager execution\n";
// ...
await gen_bar();
// this code is only executed after await
return 'result';
}
$x = gen_foo(); // x is a handle, suspended at the point of its first 'await'
await $x; // ... and now it's resumed
The benefit comes from being able to batch these async functions together: list($x, $y, $z) = await genva(
gen_foo(),
gen_bar(),
gen_baz();
); // genva creates a wait handle for awaiting its args
// ... and when we get here $x, $y, and $z are all assigned
(I'm not a php developer so excuse my ignorance)
It seems you only have 1 method 'await', to check if the async function has completed its job (it self, if I'm understanding is a blocking operation in which ever thread/worker its called).
So is there a way to run something more similar to
Because as I see it now, what ever I run asynchronously I.E.: I'm forced to time out my async calls so that they'll rendezvous in the same place won't I?Again if I'm completely off the mark please let me know.