launch {
val data = fetchFromNetwork().map { it.toModel() }
withContext(Main) {
updateUi(data)
}
}
launch {
fetchData()
.map { it.toModel() }
.alsoOn(Main) { data ->
updateUi(data)
}
}
suspend fun <T, R> T.letOn( | |
context: CoroutineContext, | |
block: suspend CoroutineScope.(T) -> R | |
): R = withContext(context) { block(this@letOn) } | |
suspend fun <T> T.alsoOn( | |
context: CoroutineContext, | |
block: suspend CoroutineScope.(T) -> Unit | |
): T = also { withContext(context) { block(this@alsoOn) } } | |
suspend fun <T> T.applyOn( | |
context: CoroutineContext, | |
block: suspend T.(CoroutineScope) -> Unit | |
): T = apply { withContext(context) { [email protected](this) } } | |
suspend fun <T, R> T.runOn( | |
context: CoroutineContext, | |
block: suspend T.(CoroutineScope) -> R | |
): R = withContext(context) { [email protected](this) } |