17
17
package kotlinx.coroutines.experimental.rx2
18
18
19
19
import io.reactivex.Flowable
20
+ import kotlinx.coroutines.experimental.CoroutineDispatcher
21
+ import kotlinx.coroutines.experimental.CoroutineScope
22
+ import kotlinx.coroutines.experimental.DefaultDispatcher
23
+ import kotlinx.coroutines.experimental.Job
20
24
import kotlinx.coroutines.experimental.channels.ProducerScope
21
25
import kotlinx.coroutines.experimental.reactive.publish
26
+ import kotlin.coroutines.experimental.ContinuationInterceptor
22
27
import kotlin.coroutines.experimental.CoroutineContext
23
28
24
29
/* *
25
30
* Creates cold [flowable][Flowable] that will run a given [block] in a coroutine.
26
- * Every time the returned flowable is subscribed, it starts a new coroutine in the specified [context] .
31
+ * Every time the returned flowable is subscribed, it starts a new coroutine.
27
32
* Coroutine emits items with `send`. Unsubscribing cancels running coroutine.
28
33
*
29
34
* Invocations of `send` are suspended appropriately when subscribers apply back-pressure and to ensure that
@@ -34,8 +39,18 @@ import kotlin.coroutines.experimental.CoroutineContext
34
39
* | `send` | `onNext`
35
40
* | Normal completion or `close` without cause | `onComplete`
36
41
* | Failure with exception or `close` with cause | `onError`
42
+ *
43
+ * The [context] for the new coroutine can be explicitly specified.
44
+ * See [CoroutineDispatcher] for the standard context implementations that are provided by `kotlinx.coroutines`.
45
+ * The [context][CoroutineScope.context] of the parent coroutine from its [scope][CoroutineScope] may be used,
46
+ * in which case the [Job] of the resulting coroutine is a child of the job of the parent coroutine.
47
+ * If the context does not have any dispatcher nor any other [ContinuationInterceptor], then [DefaultDispatcher] is used.
48
+ *
49
+ * @param context context of the coroutine. The default value is [DefaultDispatcher].
50
+ * @param block the coroutine code.
37
51
*/
52
+ @JvmOverloads // for binary compatibility with older code compiled before context had a default
38
53
public fun <T > rxFlowable (
39
- context : CoroutineContext ,
54
+ context : CoroutineContext = DefaultDispatcher ,
40
55
block : suspend ProducerScope <T >.() -> Unit
41
56
): Flowable <T > = Flowable .fromPublisher(publish(context, block))
0 commit comments