What is the best way to schedule tasks on an inter...
# compose-desktop
c
What is the best way to schedule tasks on an interval within the context of a certain composable? Meaning the task only runs while the composable is on screen.
b
Launched effect with infinite loop and delay?
z
By “on screen” do you mean composed or actually visible, ie not clipped by any of its parents?
c
Composed
s
Then exactly what Martynas said. A simple
LaunchedEffect(Unit)
and wrap your thing inside a
Copy code
while(isActive) {
  //your stuff
  delay(1_000)
}
Things will just work plus cancel themselves due to automatic cancellation (if the things you call cooperate with cancellation as well).
c
Thanks all 🙂