I’m using the following code to run an action repe...
# coroutines
z
I’m using the following code to run an action repeatedly on an interval:
Copy code
internal 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:
Copy code
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:
Copy code
@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