async and await
async is a coroutine builder that can be used as an alternative to launch. Much like launch, async accepts a lambda expression as an argument, which is where you can call other code that suspends. The big difference between these two functions is their return types: launch returns a Job, but async returns an instance of Deferred.
These two classes are similar – in fact, Deferred extends from Job. But in addition to including information about the status of the coroutine, Deferred will also get a hold of the value returned by the coroutine. A Deferred value represents a value that might not be ready at this moment, but will be available eventually. The Deferred that is returned by async will receive whatever value ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access