Thread
#exposed
    b

    bitkid

    3 years ago
    Database.connect(datasource = HikariDataSource(poolConfig),
                manager = { ThreadLocalTransactionManager(it, Connection.TRANSACTION_REPEATABLE_READ, 0) })
    what i am doing (which i have no idea if it's sane) is the follwing. i have a small helper method which moves the transaction the IO Dispatcher
    suspend fun <T> dbTransaction(database: Database, block: () -> T): TransactionResult<T> =
        suspendedTransactionAsync(<http://Dispatchers.IO|Dispatchers.IO>, database, false) {
            block()
        }
    and in my route handlers look like this
    fun Route.logIn(database: Database, sessionHandler: SessionHandler) {
        post<Login> {
            val response = dbTransaction(database) {
                sessionHandler.login(data)
            }.await()
            call.respond(response)
        }
    }
    so i can either wait for the db stuff to return with await() or i don't (fire and forget)
    i am wondering if it actually makes sense to use Dispatchers.IO .. as it will most probably use the current thread from DefaultDispatcher
    @tapac this is how i am using it now with ktor
    btw my code fails when i pass true to suspendedTransactionAsync .. with a connection closed exception
    tapac

    tapac

    3 years ago
    @bitkid Could you please share a little sample which I could run to test your case?