https://kotlinlang.org logo
#announcements
Title
# announcements
v

vaskir

07/03/2017, 1:12 PM
Copy code
suspend fun <T> withTimeout(timeout: Long, units: TimeUnit, f: () -> Deferred<T>) : T? {
    val d = f()
    return select {
        d.onAwait { it }
        onTimeout(timeout, units) {
            d.cancel()
            throw TimeoutException()
        }
    }
}