There's little downside to having this exposed as an extension method 
(extension methods can only access public members but not an issue here), 
and I think that's really the only reasonable way to do it. Technically I 
could provide a TransactionalCallable with a runBlocking{} inside it, and 
that would compile, but also lose much of the benefits of using coroutines 
(won't carry over coroutine context, ties up a thread). Instead, I threw 
together a quick proof of concept of one way it could work: 
https://github.com/jOOQ/jOOQ/compare/master...marshallpierce:kotlin-suspend-txn-result?expand=1

This way does work and was "easy", but now there's essentially a duplicated 
copy of `transactionResult0`, which is pretty sad, and it's in 
`org.jooq.impl` to get access to DefaultTransactionContext and friends, 
creating a split package which will make JPMS upset.

If there was another way to implement the listener stuff before and 
exception stuff after that didn't involve package-private classes (and 
hopefully also avoiding copy-and-paste code...), then the extension 
function could be in a separate package, and indeed a separate project 
entirely. Or, if there isn't an option to use public types, could *gasp* 
actually use JPMS to expose the org.jooq.impl package to 
org.jooq.kotlin_stuff_goes_here. Mark Reinhold would be so happy.

On Tuesday, October 1, 2019 at 12:47:38 AM UTC-6, Lukas Eder wrote:
>
> Hi Marshall,
>
> Thank you very much for your suggestion. Is that something you think would 
> be easy to integrate in jOOQ without adding a dependency on Kotlin 
> libraries? How does supporting that out of the box compare to an extension 
> method (at least for now)? I would imagine that this could be implemented 
> entirely outside of jOOQ, too...
>
> Thanks,
> Lukas
>
> On Mon, Sep 30, 2019 at 4:39 PM Marshall Pierce <[email protected] 
> <javascript:>> wrote:
>
>> One more...
>>
>> It'd make integration with Kotlin coroutines (OK, that's not just Kotlin 
>> the language...) easier/possible to have something like `transactionResult` 
>> that instead of taking a `TransactionCallable` and doing all the 
>> ManagedBlocker bits, took something whose `run()` (or equivalent) was a 
>> `suspend` function. In Kotlinese, that could be simply a function type: 
>> `suspend (Configuration) -> T`.
>>
>> My current use case is that I'd like to be able to kick off some 
>> fire-and-forget async work inside a transaction, and for various reasons 
>> I'd prefer to have that be done via coroutines rather than 
>> `CompletableFuture` and friends (e.g. coroutine context carries over to 
>> child coroutines, unlike threadlocals, and other such things).
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jooq-user/0a5a7ec5-3a9a-49cc-8da9-36cd7246849b%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/jooq-user/0a5a7ec5-3a9a-49cc-8da9-36cd7246849b%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/1b0398e7-8f66-469c-96fc-78d480b9fe14%40googlegroups.com.

Reply via email to