Nick
04/13/2023, 9:41 PMval scope = rememberCoroutineScope()
DisposableEffect(Unit) {
onDispose {
// do some stuff
scope.launch { < -- could this be canceled when the call leaves the composition?
// tear down
}
}
}
Loney Chou
04/13/2023, 10:47 PMZach Klippenstein (he/him) [MOD]
04/13/2023, 11:51 PMAdam Powell
04/14/2023, 12:41 AMscope.launch
's suspend function won't have an opportunity to run before scope
is cancelled, but `onDispose {}`'s block does indeed run before that cancellation occursNick
04/14/2023, 8:38 PMrememberCoroutineScope
, rather we should use some other scope that has a longer lifecycle.
DisposableEffect(Unit) {
onDispose {
someLongerScope.launch {
cameraProvider?.unbindAll()
}
}
}
Zach Klippenstein (he/him) [MOD]
04/14/2023, 10:38 PMNonCancellable
as the context to launch. But that’s dangerous if anything could suspend, since it could leak.Adam Powell
04/18/2023, 1:52 PMonDispose
block and skip the launch entirely