Preserve coroutine context in WebClientExtensions
See gh-33548
This commit is contained in:
parent
5cc4d0a2ca
commit
478aa250a0
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.web.reactive.function.client
|
package org.springframework.web.reactive.function.client
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.reactive.asFlow
|
import kotlinx.coroutines.reactive.asFlow
|
||||||
|
@ -87,16 +89,20 @@ suspend fun RequestHeadersSpec<out RequestHeadersSpec<*>>.awaitExchange(): Clien
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
suspend fun <T: Any> RequestHeadersSpec<out RequestHeadersSpec<*>>.awaitExchange(responseHandler: suspend (ClientResponse) -> T): T =
|
suspend fun <T: Any> RequestHeadersSpec<out RequestHeadersSpec<*>>.awaitExchange(responseHandler: suspend (ClientResponse) -> T): T {
|
||||||
exchangeToMono { mono(Dispatchers.Unconfined) { responseHandler.invoke(it) } }.awaitSingle()
|
val context = currentCoroutineContext().minusKey(Job.Key)
|
||||||
|
return exchangeToMono { mono(context) { responseHandler.invoke(it) } }.awaitSingle()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variant of [WebClient.RequestHeadersSpec.awaitExchange] that allows a nullable return
|
* Variant of [WebClient.RequestHeadersSpec.awaitExchange] that allows a nullable return
|
||||||
*
|
*
|
||||||
* @since 5.3.8
|
* @since 5.3.8
|
||||||
*/
|
*/
|
||||||
suspend fun <T: Any> RequestHeadersSpec<out RequestHeadersSpec<*>>.awaitExchangeOrNull(responseHandler: suspend (ClientResponse) -> T?): T? =
|
suspend fun <T: Any> RequestHeadersSpec<out RequestHeadersSpec<*>>.awaitExchangeOrNull(responseHandler: suspend (ClientResponse) -> T?): T? {
|
||||||
exchangeToMono { mono(Dispatchers.Unconfined) { responseHandler.invoke(it) } }.awaitSingleOrNull()
|
val context = currentCoroutineContext().minusKey(Job.Key)
|
||||||
|
return exchangeToMono { mono(context) { responseHandler.invoke(it) } }.awaitSingleOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coroutines variant of [WebClient.RequestHeadersSpec.exchangeToFlux].
|
* Coroutines variant of [WebClient.RequestHeadersSpec.exchangeToFlux].
|
||||||
|
|
Loading…
Reference in New Issue