Add awaitBodyOrNull to WebClient.ResponseSpec
Such variant is already provided for ClientResponse but not for WebClient.ResponseSpec. Closes gh-26731
This commit is contained in:
committed by
Sébastien Deleuze
parent
85dbd2a4c3
commit
58e40d1aa2
@@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.reactive.asFlow
|
||||
import kotlinx.coroutines.reactive.awaitSingle
|
||||
import kotlinx.coroutines.reactive.awaitSingle
|
||||
import kotlinx.coroutines.reactive.awaitSingleOrNull
|
||||
import kotlinx.coroutines.reactor.asFlux
|
||||
import kotlinx.coroutines.reactor.mono
|
||||
import org.reactivestreams.Publisher
|
||||
@@ -143,6 +144,17 @@ suspend inline fun <reified T : Any> WebClient.ResponseSpec.awaitBody() : T =
|
||||
else -> bodyToMono<T>().awaitSingle()
|
||||
}
|
||||
|
||||
/**
|
||||
* Coroutines variant of [WebClient.ResponseSpec.bodyToMono].
|
||||
*
|
||||
* @author Valentin Shakhov
|
||||
*/
|
||||
suspend inline fun <reified T : Any> WebClient.ResponseSpec.awaitBodyOrNull() : T? =
|
||||
when (T::class) {
|
||||
Unit::class -> awaitBodilessEntity().let { Unit as T? }
|
||||
else -> bodyToMono<T>().awaitSingleOrNull()
|
||||
}
|
||||
|
||||
/**
|
||||
* Coroutines variant of [WebClient.ResponseSpec.toBodilessEntity].
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user