Art*_*r A 0 android kotlin kotlin-coroutines
fetchData()是suspendCoroutine函数,所以它是在其他线程上实现的。
viewModelScope绑定到Dispatchers.Main:这应该仅用于与 UI 交互和执行快速工作。
所以我应该delay()在Dispatcher.Main或者我应该搬出去了吗?
fun loadData() {
viewModelScope.launch {
delay(START_DELAY)
when (val result = fetchData()) {
is Response.Success<IData> -> {}
is Response.Failure -> {}
}
}
}
fun fetchData(){
return suspendCoroutine { cont ->}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
338 次 |
| 最近记录: |