ursus
11/10/2019, 7:09 PMoctylFractal
11/10/2019, 7:14 PMursus
11/10/2019, 7:18 PMfun Service.doWhatever() {
serviceScope.launch {
...
}
}
fun ViewModel.buttonClick() {
viewModelScope.launch {
service.doWhatever()
ui.displaySuccess()
}
}
octylFractal
11/10/2019, 7:19 PMursus
11/10/2019, 7:20 PMoctylFractal
11/10/2019, 7:21 PMursus
11/10/2019, 7:22 PMoctylFractal
11/10/2019, 7:22 PMursus
11/10/2019, 7:23 PMoctylFractal
11/10/2019, 7:23 PMursus
11/10/2019, 7:23 PMoctylFractal
11/10/2019, 7:25 PMursus
11/10/2019, 7:27 PMoctylFractal
11/10/2019, 7:28 PMursus
11/10/2019, 7:28 PMoctylFractal
11/10/2019, 7:29 PMursus
11/10/2019, 7:29 PMoctylFractal
11/10/2019, 7:30 PMursus
11/10/2019, 7:30 PMoctylFractal
11/10/2019, 7:31 PMursus
11/10/2019, 7:31 PMfun Viewmodel.buttonClick {
appScope.launch {
service.foo()
ui.display
}
}
doesnt this leak Ui?octylFractal
11/10/2019, 7:31 PMursus
11/10/2019, 7:31 PMoctylFractal
11/10/2019, 7:32 PMursus
11/10/2019, 7:35 PMoctylFractal
11/10/2019, 7:37 PMursus
11/10/2019, 7:38 PMoctylFractal
11/10/2019, 7:40 PMursus
11/10/2019, 7:46 PMoctylFractal
11/10/2019, 7:47 PMursus
11/10/2019, 7:55 PMoctylFractal
11/10/2019, 7:56 PMursus
11/10/2019, 8:31 PMoctylFractal
11/10/2019, 8:32 PMlaunch
block finishes... UI is GC'dkevindmoore
11/10/2019, 9:55 PMsuspend fun Service.doWhatever() {
}
fun ViewModel.buttonClick() {
viewModelScope.launch {
service.doWhatever()
ui.displaySuccess()
}
}
octylFractal
11/10/2019, 9:57 PMkevindmoore
11/10/2019, 10:01 PMursus
11/10/2019, 11:40 PMgildor
11/11/2019, 12:52 AMursus
11/11/2019, 1:49 AMsuspend fun foo() {
val deffered = scope.async {
// foo stuff
}
return deffered.await
}
this?gildor
11/11/2019, 2:29 AMursus
11/11/2019, 5:18 AMgildor
11/11/2019, 6:01 AMursus
11/11/2019, 6:09 AMIf you need to launch a coroutine that keeps running after your function returns, then make your function an extension of CoroutineScope or pass scope: CoroutineScope as parameter to make your intent clear in your function signature. Do not make these functions suspending:
https://medium.com/@elizarov/coroutine-context-and-scope-c8b255d59055gildor
11/11/2019, 6:17 AM