async and await
We'll cover the following...
Why async
& await
are used?
The launch()
function returns a Job object that can be used to await termination of the coroutine or to cancel. But there’s no way to return a result from the coroutine that was started using launch()
. If you want to execute a task asynchronously and get the response, then use async()
instead of launch()
.
The async()
function takes the same parameters as launch()
, so we can configure the context and start properties of coroutines that are created using async()
...