https://kotlinlang.org logo
#coroutines
Title
# coroutines
h

hohnjogan

01/17/2019, 10:23 PM
Messing around with coroutines for first time. Is there a better way to implement a timer that executes a block of code every x millis? I was hoping to avoid recreating the job every time but it seems that you cannot "pause" a coroutines and start it again. Thanks in advance.
n

nil2l

01/17/2019, 10:27 PM
if (!isPaused) block()
?
g

ghedeon

01/17/2019, 10:27 PM
b

bj0

01/17/2019, 10:53 PM
I don't see what's wrong with launching a new coroutine when you restart, they are lightweight
d

dave08

01/18/2019, 3:49 AM
If block is not
block: suspend () -> Unit
what's the point of the launch? You're not suspending at all...
g

gotoOla

01/18/2019, 1:03 PM
are you doing this for the learning experience or is there any reason why you don’t want to use the fixedRateTimer-extension? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.concurrent/fixed-rate-timer.html
3 Views