Hello, are there any plans to deprecate and remove...
# exposed
a
Hello, are there any plans to deprecate and remove singletons/statics from a library? Now it's complicated to use it in asynchronous environment (coroutines, multi-thread), and not sure if it's compatible with ktor
a
understood, by looking and Exposed code it seems non trivial to implement explicit transaction manager because of singletons all over place
doing some prototyping on removing singletons
t
It's not necessary to remove "Singletons" as we just have to provide thread locals into coroutine scopes but it's not obvious how to keep current behavior and provided support for
suspend
a
I think it would be better to remove all singletons and all variables which is implicitly used as global variables
because of coroutines and multi threaded environment
avoiding any glitches on race conditions and reentrant invocations
now I can seen that ThreadManager.manager global is temporary set and restored using resetCurrent()
and cannot image what would happen if production system uses this with coroutines which can simultaneously run many coroutines on the same thread
t
Yes, but every thread has it's own "current" copy of manager,
a
with thread it's ok
with coroutines which has a thread pool it's not
but, hm. maybe ok
if everything is blocking (synchronous)
t
a
currently we are trying to manage transactions to work correctly
now if execution is spawned to another thread during context switch
t
a
it gets duplicated and rollback not works properly
is this will stick current transaction manager and carry all down in a suspend function calls?
t
AFAIU within
launch
block
manager
should be the same as before entering that block on any
Dispatchers.Default
thread. But you have to provide
currentTransactionContext
into every scope where you expect to execute Exposed methods.
Like:
Copy code
launch(Dispatchers.Default + currentTransactionContext()) {
   ...
    runBlocking(<http://Dispatchers.IO|Dispatchers.IO> + currentTransactionContext()) { 
       ....
    }
}
a
got it, thanks.
is there a reason why transaction manager is different per each thread?
t
is there a reason why transaction manager is different per each thread?
You might want to work with different Databases in separate threads
a
that make sense
but TransactionManager.current(database:Database) also could be used
or it was designed to not explicitly pass database object everythere?
t
Yes, to reduce boilerplate. Possibly it was a huge design f*ckup (it was designed that way by initial creator of Exposed).
a
It feels like that 🙂
because of kotlin DSL support it could be just made more cleaner all functions just could be added as extension functions on Transaction maybe
seems like library was written for java
but I really like query builder
and overall API
t
The problem here in DAO objects as they can't be "scoped" as extension functions.