🐦 Kotlin Intermediate

What is the difference between launch and async in Kotlin coroutines?

Answer

Both are coroutine builders, but they serve different purposes. launch starts a coroutine for fire-and-forget work — it returns a Job but no result. Use it when you want to perform a side effect (save data, show a notification). async starts a coroutine that computes a result — it returns a Deferred<T>. Call await() on the Deferred to get the result, which suspends the caller until the async block completes. Use async for parallel decomposition: launch multiple async blocks and then await all results.