Add useSuspending to ConnectionPool for better Kotlin support
See original GitHub issueThe current implementation of .use
method is based on CompletableFuture
and is not Kotlin-friendly. Instead, I had to write my own implementation that looks more or less like this:
suspend fun <T, C : ConcreteConnection> ConnectionPool<C>.useSuspending(
block: suspend (SuspendingConnection) -> T
): T {
var exception: Throwable? = null
val connection = take().await()
try {
return block(connection.asSuspending)
} catch (e: Throwable) {
exception = e
throw e
} finally {
if (exception == null) {
giveBack(connection).await()
} else {
try {
giveBack(connection).await()
} catch (closeException: Throwable) {
exception.addSuppressed(closeException)
}
}
}
}
However, unlike the already provided .use
function, this implementation is not using configuration.executionContext
. Not sure how much of a problem this is.
At any rate, it would be nice to have a similar API available for Kotlin users.
P.S. I initially started with r2dbc interface for jasync, but the code ends up bloated with all of the “await” statements…
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Add Kotlin to an existing app
Android Studio provides full support for Kotlin, enabling you to add Kotlin files to your existing project and convert Java language code to ......
Read more >Web on Reactive Stack
This part of the documentation covers support for reactive-stack web applications built on a Reactive Streams API to run on non-blocking ...
Read more >What's new in Kotlin 1.6.20
To provide better interoperability when extending generic Java ... Support for parallel compilation of a single module in the JVM backend.
Read more >Using kapt
Using in Gradle · Apply the kotlin-kapt Gradle plugin: · Add the respective dependencies using the kapt configuration in your dependencies block:.
Read more >What's new in Kotlin 1.7.0
This release introduces new build reports, support for Gradle plugin variants, new statistics in kapt, and a lot more: A new approach to ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ilya40umov any update on this? would you like to add a PR?
Yes, I am looking at it.