val channel = produce {
delay(500) // only one value with delay, but can be wrapped to some loop)
send("some value")
}
for (value in channel) {
//Do something
}
Depends on your case of course. What exactly do you want to do?
👍 1
a
adibfara
02/14/2018, 8:31 AM
I'm currently learning coroutines.
Observable.interval
emits an item every x TimeUnits. for example you can emit a value every 500 miliseconds for 10 times.
From your code, I imagine it would be easy to implement, It just needs a
for
for how many times it should run and the timer needs to be inside
delay
.
Thanks.
g
gildor
02/14/2018, 8:32 AM
Yes, something like:
Copy code
val channel = produce {
repeat(10) {
delay(500)
send("some value")
}
}