What is the best way to achieve some periodic task...
# coroutines
i
What is the best way to achieve some periodic task with coroutines? I'm simply starting a coroutine with launch and using a
while (isActive)
with a delay. Is this the best approach?
v
You even don't need to check
isActive
.
delay
does it on its own
I would also recommend crating a separate thread pool for this coroutine to ensure that the threads are not blocked with something else
w
That's how I've done it, but now there is also
ticker
channel
i
@voddan, cool. I created a
newSingleThreadContext
because I need only 1 thread for the task. And it's nice to know that I don't need the
isActive
@withoutclass I'll for sure check the
ticker
channel. But I'll be glad if you have an example for that ­čśâ