Skip to content

Commit 5633f91

Browse files
committed
Moved documentation for different kinds of channels to Channel interface
1 parent 27b8f45 commit 5633f91

File tree

8 files changed

+35
-26
lines changed

8 files changed

+35
-26
lines changed

common/kotlinx-coroutines-core-common/src/channels/ArrayChannel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import kotlinx.coroutines.experimental.selects.*
1616
*
1717
* This implementation uses lock to protect the buffer, which is held only during very short buffer-update operations.
1818
* The lists of suspended senders or receivers are lock-free.
19+
*
1920
* @suppress **This an internal API and should not be used from general code.**
2021
*/
21-
@InternalCoroutinesApi // todo: review KDoc refs
22+
@InternalCoroutinesApi
2223
public open class ArrayChannel<E>
2324
@Deprecated(
2425
"Replace with Channel factory function",

common/kotlinx-coroutines-core-common/src/channels/Channel.kt

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,28 @@ public interface ChannelIterator<out E> {
321321
* Conceptually, a channel is similar to [BlockingQueue][java.util.concurrent.BlockingQueue],
322322
* but it has suspending operations instead of blocking ones and it can be closed.
323323
*
324-
* See `Channel(capacity)` factory function for the description of available channel implementations.
324+
* `Channel(capacity)` factory function is used to create channels of different kind depending on
325+
* the value of `capacity` integer:
326+
*
327+
* * When `capacity` is 0 -- it creates `RendezvousChannel`.
328+
* This channel does not have any buffer at all. An element is transferred from sender
329+
* to receiver only when [send] and [receive] invocations meet in time (rendezvous), so [send] suspends
330+
* until another coroutine invokes [receive] and [receive] suspends until another coroutine invokes [send].
331+
*
332+
* * When `capacity` is [Channel.UNLIMITED] -- it creates `LinkedListChannel`.
333+
* This is a channel with linked-list buffer of a unlimited capacity (limited only by available memory).
334+
* Sender to this channel never suspends and [offer] always returns `true`.
335+
*
336+
* * When `capacity` is [Channel.CONFLATED] -- it creates `ConflatedChannel`.
337+
* This channel buffers at most one element and conflates all subsequent `send` and `offer` invocations,
338+
* so that the receiver always gets the most recently sent element.
339+
* Back-to-send sent elements are _conflated_ -- only the the most recently sent element is received,
340+
* while previously sent elements **are lost**.
341+
* Sender to this channel never suspends and [offer] always returns `true`.
342+
*
343+
* * When `capacity` is positive, but less than [UNLIMITED] -- it creates [ArrayChannel].
344+
* This channel has an array buffer of a fixed `capacity`.
345+
* Sender suspends only when buffer is fully and receiver suspends only when buffer is empty.
325346
*/
326347
public interface Channel<E> : SendChannel<E>, ReceiveChannel<E> {
327348
/**
@@ -357,15 +378,10 @@ public fun <E> Channel(): Channel<E> = RendezvousChannel<E>()
357378

358379
/**
359380
* Creates a channel with the specified buffer capacity (or without a buffer by default).
360-
*
361-
* The resulting channel type depends on the specified [capacity] parameter:
362-
* * when `capacity` is 0 -- creates [RendezvousChannel] without a buffer;
363-
* * when `capacity` is [Channel.UNLIMITED] -- creates [LinkedListChannel] with buffer of unlimited size;
364-
* * when `capacity` is [Channel.CONFLATED] -- creates [ConflatedChannel] that conflates back-to-back sends;
365-
* * when `capacity` is positive, but less than [UNLIMITED] -- creates [ArrayChannel] with a buffer of the specified `capacity`;
366-
* * otherwise -- throws [IllegalArgumentException].
381+
* See [Channel] interface documentation for details.
382+
*
383+
* @throws IllegalArgumentException when [capacity] < -1
367384
*/
368-
// todo: docs
369385
public fun <E> Channel(capacity: Int = 0): Channel<E> =
370386
when (capacity) {
371387
0 -> RendezvousChannel()

common/kotlinx-coroutines-core-common/src/channels/ConflatedChannel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import kotlinx.coroutines.experimental.selects.*
2020
*
2121
* @suppress **This an internal API and should not be used from general code.**
2222
*/
23-
@InternalCoroutinesApi // todo: review KDoc usage
23+
@InternalCoroutinesApi
2424
public open class ConflatedChannel<E>
2525
@Deprecated(
2626
"Replace with Channel factory function",

common/kotlinx-coroutines-core-common/src/channels/LinkedListChannel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import kotlinx.coroutines.experimental.selects.*
1717
*
1818
* @suppress **This an internal API and should not be used from general code.**
1919
*/
20-
@InternalCoroutinesApi // todo: review KDoc usage
20+
@InternalCoroutinesApi
2121
public open class LinkedListChannel<E>
2222
@Deprecated(
2323
"Replace with Channel factory function",

common/kotlinx-coroutines-core-common/src/channels/Produce.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@ interface ProducerJob<out E> : ReceiveChannel<E>, Job {
5555
* Uncaught exceptions in this coroutine close the channel with this exception as a cause and
5656
* the resulting channel becomes _failed_, so that any attempt to receive from such a channel throws exception.
5757
*
58-
* The kind of the resulting channel depends on the specified [capacity] parameter:
59-
* * when `capacity` is 0 (default) -- uses [RendezvousChannel] without a buffer;
60-
* * when `capacity` is [Channel.UNLIMITED] -- uses [LinkedListChannel] with buffer of unlimited size;
61-
* * when `capacity` is [Channel.CONFLATED] -- uses [ConflatedChannel] that conflates back-to-back sends;
62-
* * when `capacity` is positive, but less than [UNLIMITED] -- uses [ArrayChannel] with a buffer of the specified `capacity`;
63-
* * otherwise -- throws [IllegalArgumentException].
58+
* The kind of the resulting channel depends on the specified [capacity] parameter.
59+
* See [Channel] interface documentation for details.
6460
*
6561
* See [newCoroutineContext] for a description of debugging facilities that are available for newly created coroutine.
6662
*

common/kotlinx-coroutines-core-common/src/channels/RendezvousChannel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import kotlinx.coroutines.experimental.*
1717
*
1818
* @suppress **This an internal API and should not be used from general code.**
1919
*/
20-
@InternalCoroutinesApi // todo: review KDoc usage
20+
@InternalCoroutinesApi
2121
public open class RendezvousChannel<E>
2222
@Deprecated(
2323
"Replace with Channel factory function",

core/kotlinx-coroutines-core/src/channels/Actor.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,8 @@ interface ActorJob<in E> : SendChannel<E> {
6161
* Uncaught exceptions in this coroutine close the channel with this exception as a cause and
6262
* the resulting channel becomes _failed_, so that any attempt to send to such a channel throws exception.
6363
*
64-
* The kind of the resulting channel depends on the specified [capacity] parameter:
65-
* * when `capacity` is 0 (default) -- uses [RendezvousChannel] without a buffer;
66-
* * when `capacity` is [Channel.UNLIMITED] -- uses [LinkedListChannel] with buffer of unlimited size;
67-
* * when `capacity` is [Channel.CONFLATED] -- uses [ConflatedChannel] that conflates back-to-back sends;
68-
* * when `capacity` is positive, but less than [UNLIMITED] -- uses [ArrayChannel] with a buffer of the specified `capacity`;
69-
* * otherwise -- throws [IllegalArgumentException].
64+
* The kind of the resulting channel depends on the specified [capacity] parameter.
65+
* See [Channel] interface documentation for details.
7066
*
7167
* See [newCoroutineContext][CoroutineScope.newCoroutineContext] for a description of debugging facilities that are available for newly created coroutine.
7268
*

core/kotlinx-coroutines-core/src/channels/TickerChannels.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum class TickerMode {
4343
* Creates a channel that produces the first item after the given initial delay and subsequent items with the
4444
* given delay between them.
4545
*
46-
* The resulting channel is a [rendezvous channel][RendezvousChannel]. When receiver from this channel does not keep
46+
* The resulting channel is a _rendezvous channel_. When receiver from this channel does not keep
4747
* up with receiving the elements from this channel, they are not being sent due to backpressure. The actual
4848
* timing behavior of ticker in this case is controlled by [mode] parameter which
4949
* is set to [TickerMode.FIXED_PERIOD] by default. See [TickerMode] for other details.

0 commit comments

Comments
 (0)