Run the block of code body
asynchronously.
Run the block of code body
asynchronously. body
may contain calls to await
when the results of
a Future
are needed; this is translated into non-blocking code.
Non-blocking await the on result of awaitable
.
Non-blocking await the on result of awaitable
. This may only be used directly within an enclosing async
block.
Internally, this will register the remainder of the code in enclosing async
block as a callback
in the onComplete
handler of awaitable
, and will *not* block a thread.
Async blocks provide a direct means to work with scala.concurrent.Future.
For example, to use an API that fetches a web page to fetch two pages and add their lengths:
Note that the in the following program, the second fetch does *not* start until after the first. If you need to start tasks in parallel, you must do so before
await
-ing a result.