2
2
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
+ @file:UseExperimental(ExperimentalTypeInference ::class )
6
+
5
7
package kotlinx.coroutines.channels
6
8
7
9
import kotlinx.coroutines.*
8
10
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
9
11
import kotlin.coroutines.*
12
+ import kotlin.experimental.*
10
13
11
14
/* *
12
15
* Scope for [produce][CoroutineScope.produce] coroutine builder.
@@ -65,11 +68,12 @@ interface ProducerJob<out E> : ReceiveChannel<E>, Job {
65
68
* @param onCompletion optional completion handler for the producer coroutine (see [Job.invokeOnCompletion]).
66
69
* @param block the coroutine code.
67
70
*/
71
+ @BuilderInference
68
72
public fun <E > CoroutineScope.produce (
69
73
context : CoroutineContext = EmptyCoroutineContext ,
70
74
capacity : Int = 0,
71
75
onCompletion : CompletionHandler ? = null,
72
- block : suspend ProducerScope <E >.() -> Unit
76
+ @BuilderInference block : suspend ProducerScope <E >.() -> Unit
73
77
): ReceiveChannel <E > {
74
78
val channel = Channel <E >(capacity)
75
79
val newContext = newCoroutineContext(context)
@@ -93,7 +97,7 @@ public fun <E> produce(
93
97
context : CoroutineContext = Dispatchers .Default ,
94
98
capacity : Int = 0,
95
99
onCompletion : CompletionHandler ? = null,
96
- block : suspend ProducerScope <E >.() -> Unit
100
+ @BuilderInference block : suspend ProducerScope <E >.() -> Unit
97
101
): ReceiveChannel <E > =
98
102
GlobalScope .produce(context, capacity, onCompletion, block)
99
103
@@ -112,7 +116,7 @@ public fun <E> produce(
112
116
capacity : Int = 0,
113
117
parent : Job ? = null,
114
118
onCompletion : CompletionHandler ? = null,
115
- block : suspend ProducerScope <E >.() -> Unit
119
+ @BuilderInference block : suspend ProducerScope <E >.() -> Unit
116
120
): ReceiveChannel <E > =
117
121
GlobalScope .produce(context + (parent ? : EmptyCoroutineContext ), capacity, onCompletion, block)
118
122
@@ -122,15 +126,15 @@ public fun <E> produce(
122
126
context : CoroutineContext = Dispatchers .Default ,
123
127
capacity : Int = 0,
124
128
parent : Job ? = null,
125
- block : suspend ProducerScope <E >.() -> Unit
129
+ @BuilderInference block : suspend ProducerScope <E >.() -> Unit
126
130
): ReceiveChannel <E > = GlobalScope .produce(context + (parent ? : EmptyCoroutineContext ), capacity, block = block)
127
131
128
132
/* * @suppress **Deprecated**: Binary compatibility */
129
133
@Deprecated(message = " Binary compatibility" , level = DeprecationLevel .HIDDEN )
130
134
public fun <E > produce (
131
135
context : CoroutineContext = Dispatchers .Default ,
132
136
capacity : Int = 0,
133
- block : suspend ProducerScope <E >.() -> Unit
137
+ @BuilderInference block : suspend ProducerScope <E >.() -> Unit
134
138
): ProducerJob <E > =
135
139
GlobalScope .produce(context, capacity, block = block) as ProducerJob <E >
136
140
@@ -141,7 +145,7 @@ public fun <E> produce(
141
145
public fun <E > buildChannel (
142
146
context : CoroutineContext ,
143
147
capacity : Int = 0,
144
- block : suspend ProducerScope <E >.() -> Unit
148
+ @BuilderInference block : suspend ProducerScope <E >.() -> Unit
145
149
): ProducerJob <E > =
146
150
GlobalScope .produce(context, capacity, block = block) as ProducerJob <E >
147
151
0 commit comments