@@ -19,6 +19,8 @@ package kotlinx.coroutines.experimental.channels
19
19
import kotlinx.coroutines.experimental.CancellationException
20
20
import kotlinx.coroutines.experimental.CoroutineScope
21
21
import kotlinx.coroutines.experimental.Job
22
+ import kotlinx.coroutines.experimental.channels.Channel.Factory.CONFLATED
23
+ import kotlinx.coroutines.experimental.channels.Channel.Factory.UNLIMITED
22
24
import kotlinx.coroutines.experimental.selects.SelectBuilder
23
25
import kotlinx.coroutines.experimental.selects.SelectInstance
24
26
import kotlinx.coroutines.experimental.selects.select
@@ -243,45 +245,57 @@ public interface ChannelIterator<out E> {
243
245
* Conceptually, a channel is similar to [BlockingQueue][java.util.concurrent.BlockingQueue],
244
246
* but it has suspending operations instead of blocking ones and it can be closed.
245
247
*
246
- * See [ Channel()][Channel.invoke] factory function for the description of available channel implementations.
248
+ * See ` Channel(capacity)` factory function for the description of available channel implementations.
247
249
*/
248
250
public interface Channel <E > : SendChannel <E >, ReceiveChannel <E > {
249
251
/* *
250
- * Factory for channels .
252
+ * Constants for channel factory function `Channel()` .
251
253
*/
252
254
public companion object Factory {
253
255
/* *
254
- * Requests channel with unlimited capacity buffer in [ Channel()][invoke] factory function --
256
+ * Requests channel with unlimited capacity buffer in ` Channel(...)` factory function --
255
257
* the [LinkedListChannel] gets created.
256
258
*/
257
259
public const val UNLIMITED = Int .MAX_VALUE
258
260
259
261
/* *
260
- * Requests conflated channel in [ Channel()][invoke] factory function --
262
+ * Requests conflated channel in ` Channel(...)` factory function --
261
263
* the [ConflatedChannel] gets created.
262
264
*/
263
265
public const val CONFLATED = - 1
264
266
265
267
/* *
266
268
* Creates a channel with the specified buffer capacity (or without a buffer by default).
267
- *
268
- * The resulting channel type depends on the specified [capacity] parameter:
269
- * * when `capacity` is 0 (default) -- creates [RendezvousChannel] without a buffer;
270
- * * when `capacity` is [UNLIMITED] -- creates [LinkedListChannel] with buffer of unlimited size;
271
- * * when `capacity` is [CONFLATED] -- creates [ConflatedChannel] that conflates back-to-back sends;
272
- * * when `capacity` is positive, but less than [UNLIMITED] -- creates [ArrayChannel] with a buffer of the specified `capacity`;
273
- * * otherwise -- throws [IllegalArgumentException].
269
+ * @suppress **Deprecated**
274
270
*/
275
- public operator fun <E > invoke (capacity : Int = 0): Channel <E > =
276
- when (capacity) {
277
- 0 -> RendezvousChannel ()
278
- UNLIMITED -> LinkedListChannel ()
279
- CONFLATED -> ConflatedChannel ()
280
- else -> ArrayChannel (capacity)
281
- }
271
+ @Deprecated(" Replaced with top-level function" , level = DeprecationLevel .HIDDEN )
272
+ public operator fun <E > invoke (capacity : Int = 0): Channel <E > = Channel (capacity)
282
273
}
283
274
}
284
275
276
+ /* *
277
+ * Creates a channel without a buffer -- [RendezvousChannel].
278
+ */
279
+ public fun <E > Channel (): Channel <E > = RendezvousChannel <E >()
280
+
281
+ /* *
282
+ * Creates a channel with the specified buffer capacity (or without a buffer by default).
283
+ *
284
+ * The resulting channel type depends on the specified [capacity] parameter:
285
+ * * when `capacity` is 0 -- creates [RendezvousChannel] without a buffer;
286
+ * * when `capacity` is [Channel.UNLIMITED] -- creates [LinkedListChannel] with buffer of unlimited size;
287
+ * * when `capacity` is [Channel.CONFLATED] -- creates [ConflatedChannel] that conflates back-to-back sends;
288
+ * * when `capacity` is positive, but less than [UNLIMITED] -- creates [ArrayChannel] with a buffer of the specified `capacity`;
289
+ * * otherwise -- throws [IllegalArgumentException].
290
+ */
291
+ public fun <E > Channel (capacity : Int ): Channel <E > =
292
+ when (capacity) {
293
+ 0 -> RendezvousChannel ()
294
+ UNLIMITED -> LinkedListChannel ()
295
+ CONFLATED -> ConflatedChannel ()
296
+ else -> ArrayChannel (capacity)
297
+ }
298
+
285
299
/* *
286
300
* Indicates attempt to [send][SendChannel.send] on [isClosedForSend][SendChannel.isClosedForSend] channel
287
301
* that was closed _normally_. A _failed_ channel rethrows the original [close][SendChannel.close] cause
0 commit comments