I have a comment an the coroutine channel API. Cu...
# coroutines
a
I have a comment an the coroutine channel API. Currently the
Channel
constructor takes a
capacity
argument of type Int.
capacity
is also used to define the type of the channel by the use of magic constants such as RENDEVOUS=0, BUFFERED=-2, UNLIMITED=Int.MAX_VALUE.
Copy code
val c1 = Channel<Int>(capacity = 15)
val c2 = Channel<Int>(capacity = RENDEVOUS) // dislike
Kotlin has the great feature of sealed classes. Wouldn't it be better to have an API like:
Copy code
// Limited(capacity: Int) and object Rendevous belong to sealed class ChannelType
val c1 = Channel<Int>(type = Limited(15))
val c2 = Channel<Int>(type = Rendevous) // Rendevous is an object here
­čĹŹ 4
Ô׼ 14
@elizarov Any opinion from JetBrains?
e
We might migrate to something like this in the future, but there is no pressing need. Channels are quite low-level anyway. Our focus right now is on flows.
In general, we tend to avoid introducing new entities (classes, etc) in our apis unless there are solid use-cases proving their need.