The Async library – SIP-22-Async
In Chapter 7, Working with Integration and Web Services, we have briefly seen how to call asynchronous web services that return a Future object. The aim of Async is to simplify asynchronous code by providing a couple of powerful constructs to deal with asynchronous code blocks and, in particular, combining several such blocks. It consists of only two constructs:
async { <expression> }: In this construct,<expression>is the code to be executed asynchronously.await { <expression returning a Future> }: This construct is included in anasyncblock. It suspends the execution of the enclosingasyncblock until the argumentFutureis completed.
An interesting characteristic of the whole async/await mechanism is that it is totally nonblocking. Although it is not really required to understand how async/await works, the exact signature of the two methods async[] and await[] are given for reference, as follows:
def async[T](body: => T) : Future...