-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Kotlin Non-Blocking #771
Comments
It would really be an excellent feature! |
This is a huge feature request, which will not be considered before
In addition, I also want to use the time when Jimmer evolves to |
I guess wrapping up the sqlClient operations with withContext(Dispatchers.VirtualOrIO) {
sql.executeQuery(...)
} Instead of making wholesale changes to the API or copying an asynchronous API with almost the same amount of work, I think it's better to look forward to virtual threads, if only for the sake of better resource utilization for IO behavior. Even though virtual threads aren't performing as well as we might expect, at least it's still trying, isn't it?
|
I think R2DBC will fade away as virtual threads mature. |
@ForteScarlet is not that simple. Mannualy using different contexts, the thread is changed arbitrarily and the common mechanisms of transaction does not support this case. For this motive, native async mechanisms (R2DBC) are the best approach. |
@JeanPoffo It's true that switching contexts does cause threads to be more alive and kicking. But with Jimmer, it has no state, doesn't care about transactions, and can also provide specific connections in almost any API. Transactions that can fail due to thread switches are usually caused by the same thing as annotated transactions(e.g. spring's I think there are many ways to compromise, such as starting a transaction in the context. withContext(Dispatchers.xxx) {
transactionManager.execute {
sql.createQuery(...) {...}
}
} Or manually control your connection and transaction. val dataSource: DataSource = ...
val newConnection = getConnection(dataSource)
try {
withContext(Dispatcher1) {
sql.createQuery(...) { ... }.execute(newConnection)
}
withContext(Dispatcher2) {
sql.entities.save(..., con = newConnection) {
// Save command DSL...
}
}
// commit when success.
newConnection.commit()
} catch (error: Throwable) {
// Rollback when error
newConnection.rollback()
}
releaseConnection(newConnection) In Kotlin, In Exposed, they also provide a solution to turn on transactions using a suspend function, although they are also JDBC-based. Of course, all this is not to deny R2DBC; if it can truly fully support R2DBC, that would definitely be a wonderful thing! However, as mentioned by @SWQXDBA, with the gradual maturation of virtual threads, the boundary between reactive programming and virtual threads in the JVM will become increasingly blurred. For Kotlin, it might be okay, but for Java, both writing and debugging with reactive APIs is not a very good experience. Regardless, the above is just my personal opinion. |
Is there any chance of adding non-blocking features? In the development of idiomatic applications in Kotlin, the use of coroutines is essential. It would be very interesting to have a data layer with the non-blocking jimmer. With an API similar to that of Micronaut Data R2DBC
The text was updated successfully, but these errors were encountered: