} sealed class DownloadStatus { data class Progress(val value: Double) : DownloadStatus() object Success : DownloadStatus() data class Error(val message: String) : DownloadStatus() }
}.switchMap { value -> flow { emit(“first $value") delay(500) emit(“second $value") } }.collect { value -> println(value) } Console output fi rst 0 fi rst 1 fi rst 2 fi rst 3 fi rst 4 fi rst 5
Unit // a lot more… } abstract class CoroutineDispatcher Dispatchers.Main Dispatchers.Default Dispatchers.IO Dispatchers.Unconfined newSingleThreadContext()
Unit // a lot more… } abstract class CoroutineDispatcher Dispatchers.Main Dispatchers.Default Dispatchers.IO Dispatchers.Unconfined newSingleThreadContext() val context: CoroutineContext = Job() + Dispatchers.IO
inline fun CoroutineScope.cancel() public fun CoroutineScope.launch(...) val ViewModel.viewModelScope: CoroutineScope val Lifecycle.coroutineScope: LifecycleCoroutineScope
= myService.getFavoriteBook(userId) book } interface MyService { @GET("{user}/books/favorite") suspend fun getFavoriteBook(@Path("user") userId: Int): Book }
= myService.getFavoriteBook(userId) book }.collect { book -> println(book) } interface MyService { @GET("{user}/books/favorite") suspend fun getFavoriteBook(@Path("user") userId: Int): Book }
= myService.getFavoriteBook(userId) book }.collect { book -> println(book) } interface MyService { @GET("{user}/books/favorite") suspend fun getFavoriteBook(@Path("user") userId: Int): Book }