vertx-lang-kotlin
vertx-lang-kotlin copied to clipboard
Dispatcher for Default Worker Pool
As the title mentions there is no coroutine dispatcher available for this, blocking workloads are only achievable through awaitBlocking call. The awaitBlocking call is a bit limiting in the sense that it expects a regular block of code, not a suspending block, so I can't:
awaitBlocking {
supendingFunction()
}
Ideally I could just
withContext(Dispatchers.VertxWorkerPool) {
}
Currently I just use the standard pools provided by the coroutines library to circumvent this but I don't really want to be wasting memory on the vertx worker pool if im not using it
I agree with CharlieTap because now it's hard to use third party library with coroutine support.
Look at the difference:
With awaitBlocking:
val result = awaitBlocking {
return@awaitBlocking transaction(db) {
<db working code>
}
}
With worker dispatcher, it would be like:
val result = suspendTransaction(vertxContext.workerDispatcher()) {
<db working code>
}
You can use Vert.executeBlocking and invoke await on the returned future.