<
Android 中 lifecyclescope viewmodelscope 协程 上下文
>
上一篇

协程 与 异常
下一篇

Viewbinding 对比 findviewbyid databinding anko

- `viewModelScope` 的上下文是 `SupervisorJob() + Dispatchers.Main.immediate`

val ViewModel.viewModelScope: CoroutineScope get() { val scope: CoroutineScope? = this.getTag(JOB_KEY) if (scope != null) { return scope } return setTagIfAbsent(JOB_KEY, CloseableCoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)) }


- `GlobalScope` 的上下文是 `EmptyCoroutineContext`

public object GlobalScope : CoroutineScope { override val coroutineContext: CoroutineContext get() = EmptyCoroutineContext } ```


Top
Foot