Hey, I'm trying to understand how to properly comb...
# exposed
s
Hey, I'm trying to understand how to properly combine transactions with suspend functions. To me it feels like the documentation is either contradicting itself or not actually showing how to work with coroutines, so I am looking for some clarifications or pointers to examples that use suspending functions. On the page https://github.com/JetBrains/Exposed/wiki/Transactions#working-with-coroutines , there is an example shown using
newSuspendedTransaction
and
withSuspendTransaction
, with comments explaining that the blocks will be run separately in "some thread from the dispatcher" (unclear if this is the same thread or multiple threads from same dispatcher) but both reusing the same transaction. However, just a couple of lines lower, there is a warning about not sharing a transaction between multiple threads. I am not sure if the example is doing just that (sharing a transaction between multiple threads), but regardless of that, I'm curious what the example would look like if there was a suspending function added to the mix, that also needs to reuse the same transaction. In order to not do https://xyproblem.info/ , I am trying to implement a standard queue using a postgres table, basically a
SELECT * FROM queue WHERE somecolumn IS NULL FOR UPDATE SKIP LOCKED
-> do some work that might or might not include suspending functions and will also need to do additional database queries, so I definitely want to reuse the existing transaction/connection -> set
somecolumn
to the finish time. Appreciate any help or pointers to examples!