-
Notifications
You must be signed in to change notification settings - Fork 682
kotlin coroutines: Improve documentation on when suspend
is required on repository methods
#2503
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
Comments
The main difference is that methods returning Methods returning
You have a valid point. We should investigate whether we can validate Coroutine repositories early so that all method either return |
As I explained in my answer in the StackOverflow question linked by you, your main concerns aren't really related to Spring Data, but rather to what does it mean that the function is But still, it seems weird to me that non-suspending delete function is not executed for you and there are no errors or warnings. If this is not a mistake then I guess this should be considered a bug in Spring. |
I do understand coroutines in Kotlin and that involves that calling a non-suspending (e.g. a repository interface I think the spring docs should not explain coroutines but how the generated repository implementations make use of them and what the "catch-ya"s are. It would be of great benefit to make this more explicit in the context of Spring Data docs by providing more hints and maybe more details on some examples so developers run less often in this. Best would be if the compiler would hint the developer, but @mp911de Yes, I think compile errors are very unlikely to be implemented. I don't know if we can detect it at runtime either but if so a hint at runtime would also be helpful. |
I created a minimal example for the delete case (see readme in the project): https://github.com/RobertHeim/spring-data-suspend-delete |
@RobertHeim where can I see the implementation details for
|
As we see in CoroutineCrudRepository most operations are marked as
suspend
. ThefindX
methods however returnFlow<X>
and are not marked assuspend
.The documentation should make more clear why and when the
suspend
is required / can/should be omitted.The doc currently states the general translation to coroutines API:
https://docs.spring.io/spring-data/r2dbc/docs/current/reference/html/#kotlin.coroutines.reactive
but from a developers perspective it would be very helpful to not only have the translation but provide it from the perspective of coroutines API (i.e. "use
suspend
for all methods unless it returns aFlow
" or am I wrong?)E.g. a non-suspending
deleteX
is not executed. In such case it also would be great to have a compile time error (but that might be not possible in the scope of the project - which is why I think it should be better documented because that is hard to catch).E.g. in reference documentation 17.5.3 Repositories it remains unclear if
findX
methods should be suspending or not and what the implications are.The text was updated successfully, but these errors were encountered: