user-documentation
user-documentation copied to clipboard
Doesn't the quads_m() function need to be 'join'ed?
Please complete the information below:
Where is the problem?
In the example code which has the function 'quads_m()'
What is the problem?
I would expect the 'quads_m()' function to be 'await'ed or in this case 'join'ed since it is an asyn function
Please don't change anything below this point.
- Build ID: 2016-10-05T21:47:03+0000:7e6e72a26df5c3d1ecc8feb244d6ef6d8d5dc924:3bcf6ed75043817b82363c6f7aa00050ccc8ff53
- Page requested: /hack/async/awaitables
- Page requested at: Thu, 08 Dec 2016 15:33:23 +0000
- Controller: GuidePageController
I'd say the example is misleading, but it does actually work properly without join
. Since quads
doesn't await
anything, it finishes completely before control returns to the calling scope — it is "eagerly executed". In the end, the program is optimized such that there is no concurrency.
@acrylic-origami is right in that it correctly runs because it is eagerly executed. It would be more correct to join the result. This way the await handle is not orphaned, and possibly never executed.
To clarify: HHVM does not run your code in parallel when you use async and await. It simply allows IO calls (like requests to a database) to be asynchronous. This means they can happen in the background and in parallel with other background tasks while your code continues to run. A well documented explanation is on the docs site.