@@ -55,26 +55,33 @@ internal fun <R> scopedFlow(@BuilderInference block: suspend CoroutineScope.(Flo
55
55
/*
56
56
* Shortcut for produce { flowScope {block() } }
57
57
*/
58
- internal fun <T > CoroutineScope.flowProduce (capacity : Int = 0, @BuilderInference block : suspend ProducerScope <T >.() -> Unit ): ReceiveChannel <T > {
58
+ internal fun <T > CoroutineScope.flowProduce (
59
+ context : CoroutineContext ,
60
+ capacity : Int = 0, @BuilderInference block : suspend ProducerScope <T >.() -> Unit
61
+ ): ReceiveChannel <T > {
59
62
val channel = Channel <T >(capacity)
60
- val newContext = newCoroutineContext(EmptyCoroutineContext ) // To have a default dispatcher and coroutine id
63
+ val newContext = newCoroutineContext(context)
61
64
val coroutine = FlowProduceCoroutine (newContext, channel)
62
65
coroutine.start(CoroutineStart .DEFAULT , coroutine, block)
63
66
return coroutine
64
-
65
67
}
66
68
67
- private class FlowCoroutine <T >(context : CoroutineContext , uCont : Continuation <T >) :
68
- ScopeCoroutine <T >(context, uCont) {
69
+ private class FlowCoroutine <T >(
70
+ context : CoroutineContext ,
71
+ uCont : Continuation <T >
72
+ ) : ScopeCoroutine<T>(context, uCont) {
69
73
70
74
public override fun childCancelled (cause : Throwable ): Boolean {
71
75
if (cause is ChildCancelledException ) return true
72
76
return cancelImpl(cause)
73
77
}
74
78
}
75
79
76
- private class FlowProduceCoroutine <T >(parentContext : CoroutineContext , channel : Channel <T >) :
77
- ProducerCoroutine <T >(parentContext, channel) {
80
+ private class FlowProduceCoroutine <T >(
81
+ parentContext : CoroutineContext ,
82
+ channel : Channel <T >
83
+ ) : ProducerCoroutine<T>(parentContext, channel) {
84
+
78
85
public override fun childCancelled (cause : Throwable ): Boolean {
79
86
if (cause is ChildCancelledException ) return true
80
87
return cancelImpl(cause)
0 commit comments