Deactivated User
12/24/2016, 1:59 PM// val line = limitedInTime(moveTimeout) { currentPlayer.readLine(charset) } // Is this going to work?
suspend fun <T> limitedInTime(timeout: TimeSpan, callback: suspend () -> T) = suspendCoroutine<T> { c ->
EventLoop.setTimeout(timeout.milliseconds.toInt()) {
c.resumeWithException(TimeoutException())
}
callback.startCoroutine(object : Continuation<T> {
override fun resume(value: T) {
c.resume(value)
}
override fun resumeWithException(exception: Throwable) {
c.resumeWithException(exception)
}
})
}
Will this work? I mean this will propagate the exception (when timedout) and cancel everything that is going in that execution?