vertx-lang-kotlin icon indicating copy to clipboard operation
vertx-lang-kotlin copied to clipboard

Dispatcher for Default Worker Pool

Open CharlieTap opened this issue 5 years ago • 2 comments

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

CharlieTap avatar Jun 25 '19 09:06 CharlieTap

I agree with CharlieTap because now it's hard to use third party library with coroutine support.

aaistom avatar Aug 28 '19 14:08 aaistom

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>
}

aaistom avatar Aug 28 '19 15:08 aaistom

You can use Vert.executeBlocking and invoke await on the returned future.

tsegismont avatar Dec 08 '22 17:12 tsegismont