question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add useSuspending to ConnectionPool for better Kotlin support

See original GitHub issue

The 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
oshaicommented, Apr 27, 2020

@ilya40umov any update on this? would you like to add a PR?

0reactions
oshaicommented, Sep 6, 2020

Yes, I am looking at it.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found