ConflatedChannel
diff --git a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/Channel.kt b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/Channel.kt
index a07ba0c..7c661c6 100644
--- a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/Channel.kt
+++ b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/Channel.kt
@@ -224,23 +224,31 @@
*/
public companion object Factory {
/**
- * Requests channel with unlimited capacity buffer in [Channel()][invoke] factory function.
+ * Requests channel with unlimited capacity buffer in [Channel()][invoke] factory function --
+ * the [LinkedListChannel] gets created.
*/
public const val UNLIMITED = Int.MAX_VALUE
/**
+ * Requests conflated channel in [Channel()][invoke] factory function --
+ * the [ConflatedChannel] gets created.
+ */
+ public const val CONFLATED = -1
+
+ /**
* Creates a channel with specified buffer capacity (or without a buffer by default).
*
* The resulting channel type depends on the specified [capacity] parameter:
* * when `capacity` is 0 -- creates [RendezvousChannel];
* * when `capacity` is [UNLIMITED] -- creates [LinkedListChannel];
+ * * when `capacity` is [CONFLATED] -- creates [ConflatedChannel];
* * otherwise -- creates [ArrayChannel].
*/
public operator fun <E> invoke(capacity: Int = 0): Channel<E> {
- check(capacity >= 0) { "Channel capacity cannot be negative, but $capacity was specified" }
return when (capacity) {
0 -> RendezvousChannel()
UNLIMITED -> LinkedListChannel()
+ CONFLATED -> ConflatedChannel()
else -> ArrayChannel(capacity)
}
}