1717package kotlinx.coroutines.experimental.rx2
1818
1919import 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
2024import kotlinx.coroutines.experimental.channels.ProducerScope
2125import kotlinx.coroutines.experimental.reactive.publish
26+ import kotlin.coroutines.experimental.ContinuationInterceptor
2227import kotlin.coroutines.experimental.CoroutineContext
2328
2429/* *
2530 * 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.
2732 * Coroutine emits items with `send`. Unsubscribing cancels running coroutine.
2833 *
2934 * Invocations of `send` are suspended appropriately when subscribers apply back-pressure and to ensure that
@@ -34,8 +39,18 @@ import kotlin.coroutines.experimental.CoroutineContext
3439 * | `send` | `onNext`
3540 * | Normal completion or `close` without cause | `onComplete`
3641 * | 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.
3751 */
52+ @JvmOverloads // for binary compatibility with older code compiled before context had a default
3853public fun <T > rxFlowable (
39- context : CoroutineContext ,
54+ context : CoroutineContext = DefaultDispatcher ,
4055 block : suspend ProducerScope <T >.() -> Unit
4156): Flowable <T > = Flowable .fromPublisher(publish(context, block))
0 commit comments