Skip to content

Instantly share code, notes, and snippets.

@jhonatansabadi
Created March 17, 2022 15:58
Show Gist options
  • Save jhonatansabadi/20483f4d8f581da754cbd1ae33ba726b to your computer and use it in GitHub Desktop.
Save jhonatansabadi/20483f4d8f581da754cbd1ae33ba726b to your computer and use it in GitHub Desktop.
public val ViewModel.viewModelScope: CoroutineScope
get() {
valscope:CoroutineScope? = this.getTag(JOB_KEY)
if(scope !=null) {
returnscope
}
return setTagIfAbsent(
JOB_KEY,
CloseableCoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment