Last active
November 10, 2020 11:17
-
-
Save manuelvicnt/6631488851c957354a60f0f10b4f442f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val JOB_KEY = "androidx.lifecycle.ViewModelCoroutineScope.JOB_KEY" | |
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment