tezvyn:

Kotlin Coroutines: async/await for Parallel Results

Source: developer.android.comintermediate

async starts a coroutine for a parallel result, returning a `Deferred` value. `await` pauses until that result is ready. Use it to run independent network calls concurrently. The footgun: using it for sequential tasks creates a needless race condition.

async starts a coroutine to compute a result in parallel, returning a `Deferred` value—a promise of a future result. `await` then pauses the current coroutine until that result is ready. This is ideal for running independent network calls concurrently, like fetching user data and preferences from different APIs to reduce total wait time. The main footgun is that an exception in an `async` block is only thrown when `await` is called, which can crash the parent coroutine unexpectedly.

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Kotlin Coroutines: async/await for Parallel Results · Tezvyn