Skip to content

WebClient.ResponseSpec.awaitEntity() prevents use of Reactor operators like retryWhen due to eager subscription #36771

@mlukasanderson

Description

@mlukasanderson

Pertaining to enhancement #34555

Description
The Kotlin coroutine extension:

suspend inline fun <reified T : Any> WebClient.ResponseSpec.awaitEntity(): ResponseEntity<T>

internally calls:

toEntity(...).awaitSingle()

This results in immediate subscription to the underlying Mono, which prevents further composition with Reactor operators such as retryWhen(Retry retrySpec)

Problem

Because awaitEntity() eagerly subscribes, the following is not possible:

webClient.get()
    .retrieve()
    .awaitEntity<Foo>() // suspends + subscribes here
    // cannot apply retryWhen after this point. Users must abandon Mono retry startegy and implement a custom alternative.
webClient.get()
    .retrieve()
    .toEntity<Foo>()
    .retryWhen(retrySpec)
    .awaitSingle() //This breaks the expectation that coroutine extensions are ergonomic equivalents of Reactor chains.

Expected Behavior

Provide an alternative API that allows retry configuration before suspension, e.g.:

awaitEntity(retrySpec...) or a non-terminal variant that allows the client code to invoke some awaitXXX() after retries are configured.

Actual Behavior
awaitEntity() hides the underlying Mono and eagerly subscribes, making it impossible to apply retryWhen or other Reactor operators afterward.

Impact

Breaks composability between Reactor and coroutines
Forces users to abandon coroutine extensions for non-trivial flows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions