Peter
02/13/2024, 4:38 PMLaunchedEffect(Unit) {
while (true) {
delay(30.seconds)
println("update")
}
}
MR3Y
02/13/2024, 4:46 PMdelay
will check for cancellation internally, and if it was already cancelled, it will terminate the while
loop. (i.e when this composable leaves the composition)Casey Brooks
02/13/2024, 4:48 PMviewModelScope
, or else create another CoroutineScope to launch it in, such as scoped to the Activity or ApplicationPeter
02/13/2024, 4:50 PMCasey Brooks
02/13/2024, 4:52 PMLaunchedEffect
are managed properly by Compose and won’t get orphaned, and Coroutines consume almost no resources while suspended, unlike Threads. So I’m guessing this probably isn’t what’s causing the problem for you.Peter
02/13/2024, 4:53 PMeygraber
02/13/2024, 5:41 PMlaunch
. If you run that code, what happens?Peter
02/13/2024, 8:32 PMlaunch()
Peter
02/13/2024, 8:36 PMlifecycle.repeatOnLifecycle { launch { ... } }
Casey Brooks
02/13/2024, 8:37 PM