Skip to content

Commit 294a836

Browse files
committed
Breaking change: make publish {...} require <T: Any>
Judging by ReactiveX/RxJava#4644, the requirement 2.13 from the reactive spec (https://github.com/reactive-streams/reactive-streams-jvm#2.13) does mean that null values can't be passed to `onNext`. Thus, it is incorrect for `publish {...}` to accept nullable values.
1 parent 87b6ab2 commit 294a836

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

reactive/kotlinx-coroutines-jdk9/src/Publish.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.reactivestreams.FlowAdapters
3333
* @throws IllegalArgumentException if the provided [context] contains a [Job] instance.
3434
*/
3535
@ExperimentalCoroutinesApi
36-
public fun <T> flowPublish(
36+
public fun <T : Any> flowPublish(
3737
context: CoroutineContext = EmptyCoroutineContext,
3838
@BuilderInference block: suspend ProducerScope<T>.() -> Unit
3939
): Flow.Publisher<T> = FlowAdapters.toFlowPublisher(publish(context, block))

reactive/kotlinx-coroutines-reactive/src/Convert.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package kotlinx.coroutines.reactive
66

7+
import kotlinx.coroutines.*
78
import kotlinx.coroutines.channels.*
89
import org.reactivestreams.*
910
import kotlin.coroutines.*
@@ -18,7 +19,10 @@ import kotlin.coroutines.*
1819
@Deprecated(message = "Deprecated in the favour of consumeAsFlow()",
1920
level = DeprecationLevel.WARNING, // Error in 1.4
2021
replaceWith = ReplaceWith("this.consumeAsFlow().asPublisher()"))
21-
public fun <T> ReceiveChannel<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Publisher<T> = publish(context) {
22-
for (t in this@asPublisher)
23-
send(t)
24-
}
22+
public fun <T> ReceiveChannel<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Publisher<T> =
23+
// we call the deprecated version here because the non-deprecated one requires <T: Any> now
24+
@Suppress("DEPRECATION_ERROR")
25+
GlobalScope.publish(context) {
26+
for (t in this@asPublisher)
27+
send(t)
28+
}

reactive/kotlinx-coroutines-reactive/src/Publish.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import kotlin.internal.*
3737
* @throws IllegalArgumentException if the provided [context] contains a [Job] instance.
3838
*/
3939
@ExperimentalCoroutinesApi
40-
public fun <T> publish(
40+
public fun <T : Any> publish(
4141
context: CoroutineContext = EmptyCoroutineContext,
4242
@BuilderInference block: suspend ProducerScope<T>.() -> Unit
4343
): Publisher<T> {

0 commit comments

Comments
 (0)