zsperske
07/06/2021, 1:19 AMinternal fun tickerFlow(period: Duration, initialDelay: Duration = Duration.ZERO) = flow {
delay(initialDelay)
while (true) {
emit(Unit)
delay(period)
}
}
In the class which uses this I call the following:
init {
tickerFlow(Duration.milliseconds(interval))
.onEach {
//do a thing
counter++
}
.launchIn(scope) //Scope is passed into my class via the constructor
}
I wrote a test to test this functionality:
@Test
fun testRepeatedWork() = runBlocking {
myClass.doThing("")
assertEquals(1, myClass.counter)
delay(5)
assertEquals(2, myClass.counter)
}
However, my test fails on the second assert, as my “tickerFlow” only seems to tick one time, despite using delay
to wait longer than the ticker’s interval