Skip to content

Commit 3ed8813

Browse files
committed
Upgrade to Coroutines 1.4.0-M1 and use awaitSingle()
This commit raises the minimum Coroutines version supported to 1.4.0-M1 and above, and changes usages of awaitFirst() or awaitFirstOrNull() to awaitSingle() or awaitSingleOrNull() to fix gh-25007. Closes gh-25914 Closes gh-25007
1 parent cd835b3 commit 3ed8813

File tree

14 files changed

+38
-38
lines changed

14 files changed

+38
-38
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ configure(allprojects) { project ->
3232
mavenBom "io.rsocket:rsocket-bom:1.1.0-RC1"
3333
mavenBom "org.eclipse.jetty:jetty-bom:9.4.32.v20200930"
3434
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.4.10"
35-
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.3.9"
35+
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.4.0-M1"
3636
mavenBom "org.junit:junit-bom:5.7.0"
3737
}
3838
dependencies {

spring-core/kotlin-coroutines/src/main/kotlin/org/springframework/core/CoroutinesUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import kotlinx.coroutines.Dispatchers
2222
import kotlinx.coroutines.GlobalScope
2323
import kotlinx.coroutines.async
2424
import kotlinx.coroutines.flow.Flow
25-
import kotlinx.coroutines.reactive.awaitFirstOrNull
25+
import kotlinx.coroutines.reactive.awaitSingleOrNull
2626
import kotlinx.coroutines.reactor.asFlux
2727

2828
import kotlinx.coroutines.reactor.mono
@@ -49,7 +49,7 @@ internal fun <T: Any> deferredToMono(source: Deferred<T>) =
4949
* @since 5.2
5050
*/
5151
internal fun <T: Any> monoToDeferred(source: Mono<T>) =
52-
GlobalScope.async(Dispatchers.Unconfined) { source.awaitFirstOrNull() }
52+
GlobalScope.async(Dispatchers.Unconfined) { source.awaitSingleOrNull() }
5353

5454
/**
5555
* Invoke a suspending function and converts it to [Mono] or [reactor.core.publisher.Flux].

spring-messaging/src/main/kotlin/org/springframework/messaging/rsocket/RSocketRequesterExtensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.springframework.messaging.rsocket
1919
import io.rsocket.transport.ClientTransport
2020
import kotlinx.coroutines.flow.Flow
2121
import kotlinx.coroutines.reactive.asFlow
22-
import kotlinx.coroutines.reactive.awaitFirstOrNull
22+
import kotlinx.coroutines.reactive.awaitSingleOrNull
2323
import kotlinx.coroutines.reactive.awaitSingle
2424
import org.reactivestreams.Publisher
2525
import org.springframework.core.ParameterizedTypeReference
@@ -103,7 +103,7 @@ inline fun <reified T : Any> RSocketRequester.RequestSpec.dataWithType(flow: Flo
103103
* @since 5.2
104104
*/
105105
suspend fun RSocketRequester.RetrieveSpec.sendAndAwait() {
106-
send().awaitFirstOrNull()
106+
send().awaitSingleOrNull()
107107
}
108108

109109
/**
@@ -122,7 +122,7 @@ suspend inline fun <reified T : Any> RSocketRequester.RetrieveSpec.retrieveAndAw
122122
* @since 5.2.1
123123
*/
124124
suspend inline fun <reified T : Any> RSocketRequester.RetrieveSpec.retrieveAndAwaitOrNull(): T? =
125-
retrieveMono(object : ParameterizedTypeReference<T>() {}).awaitFirstOrNull()
125+
retrieveMono(object : ParameterizedTypeReference<T>() {}).awaitSingleOrNull()
126126

127127
/**
128128
* Coroutines variant of [RSocketRequester.RetrieveSpec.retrieveFlux].

spring-r2dbc/src/main/kotlin/org/springframework/r2dbc/core/DatabaseClientExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
package org.springframework.r2dbc.core
1818

19-
import kotlinx.coroutines.reactive.awaitFirstOrNull
19+
import kotlinx.coroutines.reactive.awaitSingleOrNull
2020

2121
/**
2222
* Coroutines variant of [DatabaseClient.GenericExecuteSpec.then].
2323
*
2424
* @author Sebastien Deleuze
2525
*/
2626
suspend fun DatabaseClient.GenericExecuteSpec.await() {
27-
then().awaitFirstOrNull()
27+
then().awaitSingleOrNull()
2828
}
2929

3030
/**

spring-r2dbc/src/main/kotlin/org/springframework/r2dbc/core/RowsFetchSpecExtensions.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package org.springframework.r2dbc.core
1717

1818
import kotlinx.coroutines.flow.Flow
1919
import kotlinx.coroutines.reactive.asFlow
20-
import kotlinx.coroutines.reactive.awaitFirstOrNull
20+
import kotlinx.coroutines.reactive.awaitSingleOrNull
2121
import org.springframework.dao.EmptyResultDataAccessException
2222

2323
/**
@@ -26,7 +26,7 @@ import org.springframework.dao.EmptyResultDataAccessException
2626
* @author Sebastien Deleuze
2727
*/
2828
suspend fun <T> RowsFetchSpec<T>.awaitOne(): T {
29-
return one().awaitFirstOrNull() ?: throw EmptyResultDataAccessException(1)
29+
return one().awaitSingleOrNull() ?: throw EmptyResultDataAccessException(1)
3030
}
3131

3232
/**
@@ -35,24 +35,24 @@ suspend fun <T> RowsFetchSpec<T>.awaitOne(): T {
3535
* @author Sebastien Deleuze
3636
*/
3737
suspend fun <T> RowsFetchSpec<T>.awaitOneOrNull(): T? =
38-
one().awaitFirstOrNull()
38+
one().awaitSingleOrNull()
3939

4040
/**
4141
* Non-nullable Coroutines variant of [RowsFetchSpec.first].
4242
*
4343
* @author Sebastien Deleuze
4444
*/
45-
suspend fun <T> RowsFetchSpec<T>.awaitFirst(): T {
46-
return first().awaitFirstOrNull() ?: throw EmptyResultDataAccessException(1)
45+
suspend fun <T> RowsFetchSpec<T>.awaitSingle(): T {
46+
return first().awaitSingleOrNull() ?: throw EmptyResultDataAccessException(1)
4747
}
4848

4949
/**
5050
* Nullable Coroutines variant of [RowsFetchSpec.first].
5151
*
5252
* @author Sebastien Deleuze
5353
*/
54-
suspend fun <T> RowsFetchSpec<T>.awaitFirstOrNull(): T? =
55-
first().awaitFirstOrNull()
54+
suspend fun <T> RowsFetchSpec<T>.awaitSingleOrNull(): T? =
55+
first().awaitSingleOrNull()
5656

5757
/**
5858
* Coroutines [Flow] variant of [RowsFetchSpec.all].

spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/RowsFetchSpecExtensionsTests.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class RowsFetchSpecExtensionsTests {
9898
every { spec.first() } returns Mono.just("foo")
9999

100100
runBlocking {
101-
assertThat(spec.awaitFirst()).isEqualTo("foo")
101+
assertThat(spec.awaitSingle()).isEqualTo("foo")
102102
}
103103

104104
verify {
@@ -112,7 +112,7 @@ class RowsFetchSpecExtensionsTests {
112112
every { spec.first() } returns Mono.empty()
113113

114114
assertThatExceptionOfType(EmptyResultDataAccessException::class.java).isThrownBy {
115-
runBlocking { spec.awaitFirst() }
115+
runBlocking { spec.awaitSingle() }
116116
}
117117

118118
verify {
@@ -121,12 +121,12 @@ class RowsFetchSpecExtensionsTests {
121121
}
122122

123123
@Test
124-
fun awaitFirstOrNullWithValue() {
124+
fun awaitSingleOrNullWithValue() {
125125
val spec = mockk<RowsFetchSpec<String>>()
126126
every { spec.first() } returns Mono.just("foo")
127127

128128
runBlocking {
129-
assertThat(spec.awaitFirstOrNull()).isEqualTo("foo")
129+
assertThat(spec.awaitSingleOrNull()).isEqualTo("foo")
130130
}
131131

132132
verify {
@@ -135,12 +135,12 @@ class RowsFetchSpecExtensionsTests {
135135
}
136136

137137
@Test
138-
fun awaitFirstOrNullWithNull() {
138+
fun awaitSingleOrNullWithNull() {
139139
val spec = mockk<RowsFetchSpec<String>>()
140140
every { spec.first() } returns Mono.empty()
141141

142142
runBlocking {
143-
assertThat(spec.awaitFirstOrNull()).isNull()
143+
assertThat(spec.awaitSingleOrNull()).isNull()
144144
}
145145

146146
verify {

spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.web.reactive.function.client
1818

1919
import kotlinx.coroutines.flow.Flow
20-
import kotlinx.coroutines.reactive.awaitFirstOrNull
20+
import kotlinx.coroutines.reactive.awaitSingleOrNull
2121
import kotlinx.coroutines.reactive.awaitSingle
2222
import kotlinx.coroutines.reactive.asFlow
2323
import org.springframework.core.ParameterizedTypeReference
@@ -115,7 +115,7 @@ suspend fun <T : Any> ClientResponse.awaitBody(clazz: KClass<T>): T =
115115
* @since 5.2
116116
*/
117117
suspend inline fun <reified T : Any> ClientResponse.awaitBodyOrNull(): T? =
118-
bodyToMono<T>().awaitFirstOrNull()
118+
bodyToMono<T>().awaitSingleOrNull()
119119

120120
/**
121121
* `KClass` nullable coroutines variant of [ClientResponse.bodyToMono].
@@ -125,7 +125,7 @@ suspend inline fun <reified T : Any> ClientResponse.awaitBodyOrNull(): T? =
125125
* @since 5.3
126126
*/
127127
suspend fun <T : Any> ClientResponse.awaitBodyOrNull(clazz: KClass<T>): T? =
128-
bodyToMono(clazz.java).awaitFirstOrNull()
128+
bodyToMono(clazz.java).awaitSingleOrNull()
129129

130130
/**
131131
* Coroutines variant of [ClientResponse.toEntity].

spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.springframework.web.reactive.function.client
1919
import kotlinx.coroutines.Dispatchers
2020
import kotlinx.coroutines.flow.Flow
2121
import kotlinx.coroutines.reactive.asFlow
22-
import kotlinx.coroutines.reactive.awaitFirst
22+
import kotlinx.coroutines.reactive.awaitSingle
2323
import kotlinx.coroutines.reactive.awaitSingle
2424
import kotlinx.coroutines.reactor.asFlux
2525
import kotlinx.coroutines.reactor.mono
@@ -87,7 +87,7 @@ suspend fun RequestHeadersSpec<out RequestHeadersSpec<*>>.awaitExchange(): Clien
8787
* @since 5.3
8888
*/
8989
suspend fun <T: Any> RequestHeadersSpec<out RequestHeadersSpec<*>>.awaitExchange(responseHandler: suspend (ClientResponse) -> T): T =
90-
exchangeToMono { mono(Dispatchers.Unconfined) { responseHandler.invoke(it) } }.awaitFirst()
90+
exchangeToMono { mono(Dispatchers.Unconfined) { responseHandler.invoke(it) } }.awaitSingle()
9191

9292
/**
9393
* Coroutines variant of [WebClient.RequestHeadersSpec.exchangeToFlux].

spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDsl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.web.reactive.function.server
1818

1919
import kotlinx.coroutines.Dispatchers
20-
import kotlinx.coroutines.reactive.awaitFirst
20+
import kotlinx.coroutines.reactive.awaitSingle
2121
import kotlinx.coroutines.reactor.mono
2222
import org.springframework.core.io.Resource
2323
import org.springframework.http.HttpMethod
@@ -532,7 +532,7 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
532532
builder.filter { serverRequest, handlerFunction ->
533533
mono(Dispatchers.Unconfined) {
534534
filterFunction(serverRequest) {
535-
handlerFunction.handle(serverRequest).awaitFirst()
535+
handlerFunction.handle(serverRequest).awaitSingle()
536536
}
537537
}
538538
}

spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.web.reactive.function.server
1818

1919
import kotlinx.coroutines.flow.Flow
20-
import kotlinx.coroutines.reactive.awaitFirstOrNull
20+
import kotlinx.coroutines.reactive.awaitSingleOrNull
2121
import kotlinx.coroutines.reactive.awaitSingle
2222
import kotlinx.coroutines.reactive.asFlow
2323
import org.springframework.core.ParameterizedTypeReference
@@ -99,7 +99,7 @@ suspend fun <T : Any> ServerRequest.awaitBody(clazz: KClass<T>): T =
9999
* @since 5.2
100100
*/
101101
suspend inline fun <reified T : Any> ServerRequest.awaitBodyOrNull(): T? =
102-
bodyToMono<T>().awaitFirstOrNull()
102+
bodyToMono<T>().awaitSingleOrNull()
103103

104104
/**
105105
* `KClass` nullable Coroutines variant of [ServerRequest.bodyToMono].
@@ -109,7 +109,7 @@ suspend inline fun <reified T : Any> ServerRequest.awaitBodyOrNull(): T? =
109109
* @since 5.3
110110
*/
111111
suspend fun <T : Any> ServerRequest.awaitBodyOrNull(clazz: KClass<T>): T? =
112-
bodyToMono(clazz.java).awaitFirstOrNull()
112+
bodyToMono(clazz.java).awaitSingleOrNull()
113113

114114
/**
115115
* Coroutines variant of [ServerRequest.formData].
@@ -136,7 +136,7 @@ suspend fun ServerRequest.awaitMultipartData(): MultiValueMap<String, Part> =
136136
* @since 5.2
137137
*/
138138
suspend fun ServerRequest.awaitPrincipal(): Principal? =
139-
principal().awaitFirstOrNull()
139+
principal().awaitSingleOrNull()
140140

141141
/**
142142
* Coroutines variant of [ServerRequest.session].

0 commit comments

Comments
 (0)