Coroutine Basics and Scopes
Launch coroutines in the right scope.
What Are Coroutines?
Coroutines let you write asynchronous, non-blocking code in a sequential style. They are Kotlin’s answer to callbacks and threads for tasks like network and database I/O.
suspend Functions
A function marked suspend can pause without blocking the thread and resume later. It can only be called from a coroutine or another suspend function.
suspend fun fetchUser(): User {
delay(1000) // non-blocking pause
return User(1, "Ada", "ada@x.com")
}All lessons in this course
- Coroutine Basics and Scopes
- viewModelScope and Dispatchers
- Kotlin Flow Basics
- StateFlow and SharedFlow