I need a flow builder that emits `Unit` every `X` ...
# coroutines
z
I need a flow builder that emits
Unit
every
X
milliseconds while it has a subscriber. What’s the idiomatic approach for this?
s
Copy code
val flow = flow {
    while (isActive) {
        emit(Unit)
        delay(period)
    }
}
👍 2
^^^ This is a cold timer; each
flow
collector/subscriber (re-)starts the flow.
👍 2
z
yeah, would need to add
.shareIn(..)
g
Why do you need shareIn for this? It's indeed will work too, but looks that for this use case cold version also works just fine