https://kotlinlang.org logo
#server
Title
# server
l

Laurent Thiebaud

10/16/2023, 3:00 PM
Hi I am trying to use context receivers with Exposed in order to pass the transaction What would be great, would be to have optionally a transaction in the context, something like
Copy code
context(Transaction?)
fun doStatementReuseOrCreateTransaction(statement: suspend Transaction.() -> Unit) {
  if (this@Transaction == null) {
    openTransaction {
      statement()
    }
  } else statement()
}
However as soon as I make the context optional (with the
?
) then intellij is lost and doesn't understand
this@Transaction
anymore is there any way to make it work?
d

dave

10/16/2023, 3:10 PM
If you create an interface to wrap your transaction and then pass that as the context, you should be able to implement it in 2 ways - one using a transaction and one not. 🙃
l

Laurent Thiebaud

10/16/2023, 3:12 PM
😅 so easy trick thanks!
🙃 1
d

dave

10/16/2023, 3:17 PM
(there's an entire few videos on this technique)
👯‍♂️ 1
🆒 1