I’ve noticed that `eventually` contains a “busy” w...
# kotlintest
i
I’ve noticed that
eventually
contains a “busy” while loop, was thinking this might be a better implementation:
Copy code
val Duration.millis get() = this.timeUnit.toMillis(amount)

fun <T> eventually(maximumTime: io.kotlintest.Duration, pollEvery : Duration = 100.milliseconds, f: () -> T): T {
    val end = System.nanoTime() + maximumTime.nanoseconds
    var times = 0
    while (System.nanoTime() < end) {
        try {
            return f()
        } catch (e: Exception) {
            e.printStackTrace()
        }
        Thread.sleep(pollEvery.millis)
        times++
    }
    throw AssertionError("Test failed after ${maximumTime.amount} ${maximumTime.timeUnit}; attempted $times times")
}