This file contains 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
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) | |
) |
This file contains 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
scope.launch(Dispatcher.IO + Job()) |
This file contains 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
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) | |
) |
This file contains 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
public interface CoroutineScope{ | |
public valcoroutineContext:CoroutineContext | |
} |
This file contains 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
val listOfContexts = setOf<CoroutineContext>(Dispatcher.IO, Job()) |
This file contains 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
viewModelScope.launch { | |
launch { } | |
launch { } | |
launch { } | |
} |
This file contains 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
//NÃO é o viewModelScope | |
coroutineScope.launch { | |
val name = getNameFromApi() | |
val lastName = getLastNameFromApi() | |
val user = User(name, lastName) | |
//.... | |
} |
This file contains 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
//agora sim é o viewModelScope :) | |
viewModelScope.launch { | |
val name = getNameFromApi() | |
val lastName = getLastNameFromApi() | |
val user = User(name, lastName) | |
//.... | |
} |
This file contains 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
fun setUser(): User { | |
viewModelScope.launch { | |
val name = getNameFromApi() | |
val lastName = getLastNameFromApi() | |
_user.value = User(name, lastName) | |
} | |
} | |
fun setUserConfigurations(): User { | |
viewModelScope.launch { |
This file contains 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
fun setUser() { | |
viewModelScope.launch { | |
// ... | |
} | |
} |
OlderNewer