Skip to content

Commit c006a83

Browse files
committed
Upgrade to Coroutines 1.3.0-RC
This commit upgrades Coroutines support to kotlinx.coroutines 1.3.0-RC, leverages the new Coroutines BOM and refine Coroutines detection to avoid false positives. Only Coroutines to Mono context interoperability is supported for now. CLoses gh-23326
1 parent 45136aa commit c006a83

File tree

9 files changed

+17
-29
lines changed

9 files changed

+17
-29
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ext {
3030
}
3131

3232
aspectjVersion = "1.9.4"
33-
coroutinesVersion = "1.3.0-M2"
33+
coroutinesVersion = "1.3.0-RC"
3434
freemarkerVersion = "2.3.28"
3535
groovyVersion = "2.5.7"
3636
hsqldbVersion = "2.5.0"
@@ -79,6 +79,7 @@ configure(allprojects) { project ->
7979
imports {
8080
mavenBom "org.junit:junit-bom:${junit5Version}"
8181
mavenBom "org.jetbrains.kotlin:kotlin-bom:${kotlinVersion}"
82+
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:${coroutinesVersion}"
8283
}
8384
}
8485

spring-core-coroutines/spring-core-coroutines.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ dependencies {
44
compile("org.jetbrains.kotlin:kotlin-reflect")
55
compile("org.jetbrains.kotlin:kotlin-stdlib")
66
compile("io.projectreactor:reactor-core")
7-
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}")
8-
compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:${coroutinesVersion}")
7+
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core")
8+
compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
99
}
1010

1111
eclipse {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import kotlin.reflect.jvm.kotlinFunction
4040
* @since 5.2
4141
*/
4242
internal fun <T: Any> deferredToMono(source: Deferred<T>) =
43-
GlobalScope.mono(Dispatchers.Unconfined) { source.await() }
43+
mono(Dispatchers.Unconfined) { source.await() }
4444

4545
/**
4646
* Convert a [Mono] instance to a [Deferred] one.
@@ -63,7 +63,7 @@ internal fun <T: Any> monoToDeferred(source: Mono<T>) =
6363
internal fun invokeHandlerMethod(method: Method, bean: Any, vararg args: Any?): Any? {
6464
val function = method.kotlinFunction!!
6565
return if (function.isSuspend) {
66-
val mono = GlobalScope.mono(Dispatchers.Unconfined) {
66+
val mono = mono(Dispatchers.Unconfined) {
6767
function.callSuspend(bean, *args.sliceArray(0..(args.size-2)))
6868
.let { if (it == Unit) null else it }
6969
}.onErrorMap(InvocationTargetException::class.java) { it.targetException }

spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*
4848
* <p>By default, depending on classpath availability, adapters are registered
4949
* for Reactor, RxJava 1, RxJava 2 types, {@link CompletableFuture}, Java 9+
50-
* {@code Flow.Publisher} and Kotlin Coroutines {@code Deferred}.
50+
* {@code Flow.Publisher} and Kotlin Coroutines {@code Deferred} and {@code Flow}.
5151
*
5252
* @author Rossen Stoyanchev
5353
* @author Sebastien Deleuze
@@ -97,13 +97,9 @@ public ReactiveAdapterRegistry() {
9797
// We can fall back on "reactive-streams-flow-bridge" (once released)
9898

9999
// Coroutines
100-
if (this.reactorPresent && ClassUtils.isPresent("kotlinx.coroutines.Deferred", classLoader)) {
100+
if (this.reactorPresent && ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt", classLoader) && ClassUtils.isPresent("kotlinx.coroutines.reactive.flow.PublisherAsFlowKt", classLoader)) {
101101
new CoroutinesRegistrar().registerAdapters(this);
102102
}
103-
// TODO Use a single CoroutinesRegistrar when Flow will be not experimental anymore
104-
if (this.reactorPresent && ClassUtils.isPresent("kotlinx.coroutines.flow.Flow", classLoader)) {
105-
new CoroutinesFlowRegistrar().registerAdapters(this);
106-
}
107103
}
108104

109105

@@ -353,19 +349,12 @@ void registerAdapters(ReactiveAdapterRegistry registry) {
353349
() -> CompletableDeferredKt.CompletableDeferred(null)),
354350
source -> CoroutinesUtils.deferredToMono((Deferred<?>) source),
355351
source -> CoroutinesUtils.monoToDeferred(Mono.from(source)));
356-
}
357-
}
358-
359352

360-
private static class CoroutinesFlowRegistrar {
361-
362-
void registerAdapters(ReactiveAdapterRegistry registry) {
363353
registry.registerReactiveType(
364354
ReactiveTypeDescriptor.multiValue(kotlinx.coroutines.flow.Flow.class, FlowKt::emptyFlow),
365355
source -> FlowAsPublisherKt.from((kotlinx.coroutines.flow.Flow<?>) source),
366356
PublisherAsFlowKt::from
367357
);
368358
}
369359
}
370-
371360
}

spring-messaging/spring-messaging.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ dependencies {
1818
optional("io.rsocket:rsocket-transport-netty:${rsocketVersion}")
1919
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
2020
optional("javax.xml.bind:jaxb-api:2.3.1")
21-
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}")
22-
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:${coroutinesVersion}")
21+
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
22+
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
2323
testCompile("javax.inject:javax.inject-tck:1")
2424
testCompile("javax.servlet:javax.servlet-api:4.0.1")
2525
testCompile("javax.validation:validation-api:1.1.0.Final")

spring-test/spring-test.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ dependencies {
5353
optional("org.jetbrains.kotlin:kotlin-reflect")
5454
optional("org.jetbrains.kotlin:kotlin-stdlib")
5555
optional("io.projectreactor:reactor-test")
56-
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}")
57-
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:${coroutinesVersion}")
56+
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
57+
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
5858
testCompile(project(":spring-context-support"))
5959
testCompile(project(":spring-oxm"))
6060
testCompile("javax.annotation:javax.annotation-api:1.3.2")

spring-webflux/spring-webflux.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ dependencies {
4141
optional("org.jetbrains.kotlin:kotlin-reflect")
4242
optional("org.jetbrains.kotlin:kotlin-stdlib")
4343
optional("com.google.protobuf:protobuf-java-util:3.9.0")
44-
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}")
45-
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:${coroutinesVersion}")
44+
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
45+
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
4646
testCompile("javax.xml.bind:jaxb-api:2.3.1")
4747
testCompile("com.fasterxml:aalto-xml:1.1.1")
4848
testCompile("org.hibernate:hibernate-validator:6.0.17.Final")

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

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

1919
import kotlinx.coroutines.Dispatchers
20-
import kotlinx.coroutines.GlobalScope
2120
import kotlinx.coroutines.reactor.mono
2221
import org.springframework.core.io.Resource
2322
import org.springframework.http.HttpMethod
@@ -421,7 +420,7 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
421420
*/
422421
fun resources(lookupFunction: suspend (ServerRequest) -> Resource?) {
423422
builder.resources {
424-
GlobalScope.mono(Dispatchers.Unconfined) {
423+
mono(Dispatchers.Unconfined) {
425424
lookupFunction.invoke(it)
426425
}
427426
}
@@ -436,7 +435,7 @@ class CoRouterFunctionDsl(private val init: (CoRouterFunctionDsl.() -> Unit)) {
436435
}
437436

438437
private fun asHandlerFunction(init: suspend (ServerRequest) -> ServerResponse) = HandlerFunction {
439-
GlobalScope.mono(Dispatchers.Unconfined) {
438+
mono(Dispatchers.Unconfined) {
440439
init(it)
441440
}
442441
}

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

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

1919
import kotlinx.coroutines.Dispatchers
20-
import kotlinx.coroutines.GlobalScope
2120
import kotlinx.coroutines.reactive.awaitSingle
2221
import kotlinx.coroutines.reactor.mono
2322
import org.springframework.http.codec.multipart.Part
@@ -69,4 +68,4 @@ suspend fun ServerWebExchange.awaitSession(): WebSession =
6968
* @since 5.2
7069
*/
7170
fun ServerWebExchange.Builder.principal(supplier: suspend () -> Principal): ServerWebExchange.Builder
72-
= principal(GlobalScope.mono(Dispatchers.Unconfined) { supplier.invoke() })
71+
= principal(mono(Dispatchers.Unconfined) { supplier.invoke() })

0 commit comments

Comments
 (0)