andrewoma / coroutine-jdbc Goto Github PK
View Code? Open in Web Editor NEWAn experiment in bridging blocking JDBC calls with Kotlin coroutines.
An experiment in bridging blocking JDBC calls with Kotlin coroutines.
The current use for transactions in the example looks like this:
transaction(db) { tx ->
dao.insert(tx, kate)
assertThat(dao.findActresses(tx).count()).isEqualTo(1)
}
While the variable above is named tx
, it is actually represented by the generic type CoroutineContext
, which is suboptimal.
Have you considered the following alternative usage that is similar to the way thread-based transactions are usually implemented?
transaction(db) { // context is implicit, the block has no arguments
dao.insert(kate)
assertThat(dao.findActresses().count()).isEqualTo(1)
}
The difference is that we don't explicitly pass context into insert
and other dao
functions. Instead, we define the following helper function:
import kotlin.coroutines.expertimental.intrinsics.suspendCororoutineOrReturn
suspend fun coroutineContext(): CoroutineContext = suspendCororoutineOrReturn { it.context }
and use this function inside DAO to retrieve the current context (with transaction if it was started) whenever we need it.
See also this issue: https://youtrack.jetbrains.com/issue/KT-17609
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.