Hack Adds Async Cooperative Multitasking For Fake Multi-Threading
The latest addition to Facebook's PHP-based Hack programming language is an interesting concept of cooperative multitasking for providing threading-like capabilities while only really executing one piece of code at a time.
Hack's Async Cooperative Multitasking support isn't for providing real multi-threaded support but only executes one block of code at a time while being smarter about downtime for code while being blocked by waiting on requests. Namely, while one block of code could be waiting on an HTTP request or database query to be processed, another block of Hack code can be running in the intervening time.
The cooperative multitasking allows for other code to be executed while waiting for HTTP/database responses to be processed. Supported Hack code can be annotated with marking a function as "async" and use the await, WaitHandle, and Awaitable structures.
In the near-term, Facebook developers are looking to allow the cooperative multitasking to work for Streams, MySQL, WebScaleSQL, and memcached. The async feature is present in HHVM 3.5 and is still considered under active development.
Those wishing to learn more about Hack's cooperative multitasking can read this HHVM blog post.
Hack's Async Cooperative Multitasking support isn't for providing real multi-threaded support but only executes one block of code at a time while being smarter about downtime for code while being blocked by waiting on requests. Namely, while one block of code could be waiting on an HTTP request or database query to be processed, another block of Hack code can be running in the intervening time.
The cooperative multitasking allows for other code to be executed while waiting for HTTP/database responses to be processed. Supported Hack code can be annotated with marking a function as "async" and use the await, WaitHandle, and Awaitable structures.
In the near-term, Facebook developers are looking to allow the cooperative multitasking to work for Streams, MySQL, WebScaleSQL, and memcached. The async feature is present in HHVM 3.5 and is still considered under active development.
Those wishing to learn more about Hack's cooperative multitasking can read this HHVM blog post.
6 Comments