Skip to content

kotlin coroutines: Improve documentation on when suspend is required on repository methods #2503

Closed
@RobertHeim

Description

@RobertHeim

As we see in CoroutineCrudRepository most operations are marked as suspend. The findX methods however return Flow<X> and are not marked as suspend.

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:

For return values, the translation from Reactive to Coroutines APIs is the following:

fun handler(): Mono<Void> becomes suspend fun handler()

fun handler(): Mono<T> becomes suspend fun handler(): T or suspend fun handler(): T? depending on if the Mono can be empty or not (with the advantage of being more statically typed)

fun handler(): Flux<T> becomes fun handler(): Flow<T>

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 a Flow" 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions