Skip to content

Commit

Permalink
reintroduce overload for eventually to keep backwards compatibility (#34
Browse files Browse the repository at this point in the history
)
  • Loading branch information
helmbold authored and sksamuel committed Jul 3, 2016
1 parent db679f3 commit 24c6485
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/kotlin/io/kotlintest/Eventually.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.kotlintest

import java.util.concurrent.TimeUnit

interface Eventually {

fun eventually(duration: Duration, f: () -> Unit): Unit {
Expand All @@ -16,4 +18,19 @@ interface Eventually {
}
throw TestFailedException("Test failed after ${duration.amount} ${duration.timeUnit}; attempted $times times")
}

@Deprecated("use the overload with Duration instead", replaceWith = ReplaceWith("eventually(duration, f)"))
fun eventually(duration: Long, unit: TimeUnit, f: () -> Unit): Unit {
val end = System.nanoTime() + unit.toNanos(duration)
var times = 0
while (System.nanoTime() < end) {
try {
f()
return
} catch (e: Exception) {
}
times++
}
throw TestFailedException("Test failed after $duration $unit; attempted $times times")
}
}

0 comments on commit 24c6485

Please sign in to comment.