Reputation: 435
In one part of my application I post runnable to a Handler, then the code inside run()
executes and posts the same runnable to Handler with postDelayed()
. This creates something like loop. Is this behaviour achievable with coroutines? I tried to use channel, but I couldn't get it to work.
Upvotes: 3
Views: 1989
Reputation: 200138
Is this behaviour achievable with coroutines?
Yes, and in an almost embarrassingly straightforward way:
launch(UI) {
while (!done()) {
// loop body
delay(loopDelayMillis)
}
}
Upvotes: 2