asad.awadia
02/16/2018, 2:00 AMThread.sleep
isn't blocking its suspending the coroutine?dave08
02/16/2018, 3:27 AMawaitBlocking
call
* - when an exception is thrown, it is thrown from the awaitBlocking
call
*
* * val s = awaitBlocking {
* Thread.sleep(1000)
* "some-string"
* }
*
*
* The coroutine will be suspend until the block is executed, this action do not block vertx's eventLoop.
*
From the function docs... it blocks its thread in a worker thread, it just doesn't block the event loop. Of course, it's always better to use delay for that, only non-async long running computations should be run on workersdave08
02/16/2018, 3:29 AMasad.awadia
02/16/2018, 4:30 PMdave08
02/17/2018, 5:15 PMsuspend fun <T> awaitBlocking(block: () -> T) : T {
return awaitResult<T> { handler ->
val ctx = Vertx.currentContext()
ctx.executeBlocking<T>({ fut ->
fut.complete(block())
}, { ar ->
handler.handle(ar)
})
}
}