KtKotlin · Lesson 6 of 8
Coroutines — async Made Simple
Fetch from the network without freezing the UI — the core problem of app development. Coroutines let you write asynchronous code that reads exactly like synchronous code.
delay() suspends the coroutine but frees the thread to do other work — unlike Thread.sleep(), which blocks it. launch starts a fire-and-forget coroutine; async starts one that returns a value you await. Structured concurrency means coroutines launched in a scope are cancelled with it — no leaked background work.
◆ Note
Compare with JavaScript: suspend fun ≈ async function, await() ≈ await. The big extra is structured concurrency — parents own their children, cancellation propagates, and 'forgotten' background tasks can't outlive the screen that started them.
Compare with JavaScript: suspend fun ≈ async function, await() ≈ await. The big extra is structured concurrency — parents own their children, cancellation propagates, and 'forgotten' background tasks can't outlive the screen that started them.