Hey, is there any advantage `ticker` over `delay` ...
# coroutines
m
Hey, is there any advantage
ticker
over
delay
🙂? It looks like ticker just sending a Unit to channel after some delay.
z
Ticket repeatedly sends a value, delay just suspends once.
Unless you have some particular reason for using a channel, it's probably simpler to just use delay in a loop
m
I thought so, thanks a lot 🙂
c
The ticker is currently JVM-only as it doesn’t strictly follow the “structured concurrency” patterns. But the advantage of
ticker
over
delay
in a loop is that also handles slow clients and attempts to emit events with the same period, rather than delaying by a fixed amount of time
z
I believe there are plans to introduce a similar ticker for Flow, which should play a lot nicer with structured concurrency.
m
Now I see TickerMode.FIXED_PERIOD, so the ticker is a bit better if we have slow and fast hardware and we want to show e.g the animations with the same period/time on each one, anyway in most cases it shouldn't really matter