Reactive scopeless (#1341)
Make all reactive builders top-level functions instead of extensions on CoroutineScope and prohibit jobs in their context
Downsides of having lifecycle-managed scoped builders:
* The lifecycle of semantically cold entity is managed externally by the hot-one.
* Independent failures in independent triggered computations affect each other
* Two cancellation sources should be managed, coroutine-related Job parent and disposable/subscription
diff --git a/reactive/kotlinx-coroutines-rx2/test/guide/example-reactive-operators-04.kt b/reactive/kotlinx-coroutines-rx2/test/guide/example-reactive-operators-04.kt
index c57e78f..12d9c1f 100644
--- a/reactive/kotlinx-coroutines-rx2/test/guide/example-reactive-operators-04.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/guide/example-reactive-operators-04.kt
@@ -10,7 +10,7 @@
import org.reactivestreams.*
import kotlin.coroutines.*
-fun <T> Publisher<Publisher<T>>.merge(context: CoroutineContext) = GlobalScope.publish<T>(context) {
+fun <T> Publisher<Publisher<T>>.merge(context: CoroutineContext) = publish<T>(context) {
collect { pub -> // for each publisher collected
launch { // launch a child coroutine
pub.collect { send(it) } // resend all element from this publisher
@@ -33,5 +33,5 @@
}
fun main() = runBlocking<Unit> {
- testPub().merge(coroutineContext).collect { println(it) } // print the whole stream
+ testPub().merge(Dispatchers.Unconfined).collect { println(it) } // print the whole stream
}