https://kotlinlang.org logo
Title
j

jschneider

05/15/2019, 1:30 PM
Hi guys. Need some help with coroutines. I want to achieve something: From one (or many coroutines / threads) something is marked as dirty. Another coroutine waits for that marker and starts a (long running) calculation. I want to have two things: - the calculation should only run at most once per second - I do not care how often the dirty marker is set (probably very often). I just want to calculate once.
m

marstran

05/15/2019, 1:36 PM
Do you want to run it once per second, or only once ever? The two points seems to contradict each other 🙂
j

jschneider

05/15/2019, 1:37 PM
At most once per second. But only if the dirty marker is set
Idea: Some data is processed in the background. But the UI is updated (at most) once per second
So when the consumer coroutine start to run, the dirty marker is set back to false
only if the dirty marker is set to true again, it will run again
But maybe I am missing something. Maybe in the coroutines world I have to transfer the data in a channel?
m

marstran

05/15/2019, 1:38 PM
Right. Maybe some combination of a conflated channel and a ticker channel will work?
j

jschneider

05/15/2019, 1:39 PM
"Conflated channel" might be the thing I am looking for. Thanks for that hint. Will read it up
👍 1