Skip to content

Commit 9556242

Browse files
committed
Reword the concept of a channel closed without cause in docs
1 parent 5ca0d12 commit 9556242

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/Channel.kt

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ import kotlinx.coroutines.experimental.yield
3232
public interface SendChannel<in E> {
3333
/**
3434
* Returns `true` if this channel was closed by invocation of [close] and thus
35-
* the [send] attempt throws [ClosedSendChannelException]. If the channel was closed because of the exception, it
36-
* is considered closed, too, but it is called a _failed_ channel. All suspending attempts to send
37-
* an element to a failed channel throw the original [close] cause exception.
35+
* the [send] and [offer] attempts throws exception.
3836
*/
3937
public val isClosedForSend: Boolean
4038

@@ -46,8 +44,7 @@ public interface SendChannel<in E> {
4644

4745
/**
4846
* Adds [element] into to this channel, suspending the caller while this channel [isFull],
49-
* or throws [ClosedSendChannelException] if the channel [isClosedForSend] _normally_.
50-
* It throws the original [close] cause exception if the channel has _failed_.
47+
* or throws exception if the channel [isClosedForSend] (see [close] for details).
5148
*
5249
* Note, that closing a channel _after_ this function had suspended does not cause this suspended send invocation
5350
* to abort, because closing a channel is conceptually like sending a special "close token" over this channel.
@@ -76,17 +73,14 @@ public interface SendChannel<in E> {
7673
* as parameter is sent to the channel. When the clause is selected the reference to this channel
7774
* is passed into the corresponding block.
7875
*
79-
* The [select] invocation fails with [ClosedSendChannelException] if the channel
80-
* [isClosedForSend][SendChannel.isClosedForSend] _normally_ or with the original
81-
* [close][SendChannel.close] cause exception if the channel has _failed_.
76+
* The [select] invocation fails with exception if the channel [isClosedForSend] (see [close] for details).
8277
*/
8378
public val onSend: SelectClause2<E, SendChannel<E>>
8479

8580
/**
8681
* Adds [element] into this queue if it is possible to do so immediately without violating capacity restrictions
8782
* and returns `true`. Otherwise, it returns `false` immediately
88-
* or throws [ClosedSendChannelException] if the channel [isClosedForSend] _normally_.
89-
* It throws the original [close] cause exception if the channel has _failed_.
83+
* or throws exception if the channel [isClosedForSend] (see [close] for details).
9084
*/
9185
public fun offer(element: E): Boolean
9286

@@ -98,9 +92,9 @@ public interface SendChannel<in E> {
9892
* on the side of [ReceiveChannel] starts returning `true` only after all previously sent elements
9993
* are received.
10094
*
101-
* A channel that was closed without a [cause], is considered to be _closed normally_.
102-
* A channel that was closed with non-null [cause] is called a _failed channel_. Attempts to send or
103-
* receive on a failed channel throw this cause exception.
95+
* A channel that was closed without a [cause] throws [ClosedSendChannelException] on attempts to send or receive.
96+
* A channel that was closed with non-null [cause] is called a _failed_ channel. Attempts to send or
97+
* receive on a failed channel throw the specified [cause] exception.
10498
*/
10599
public fun close(cause: Throwable? = null): Boolean
106100
}
@@ -150,15 +144,14 @@ public interface ReceiveChannel<out E> {
150144
/**
151145
* Clause for [select] expression of [receive] suspending function that selects with the element that
152146
* is received from the channel.
153-
* The [select] invocation fails with [ClosedReceiveChannelException] if the channel
154-
* [isClosedForReceive][ReceiveChannel.isClosedForReceive] _normally_ or with the original
155-
* [close][SendChannel.close] cause exception if the channel has _failed_.
147+
* The [select] invocation fails with exception if the channel
148+
* [isClosedForReceive] (see [close][SendChannel.close] for details).
156149
*/
157150
public val onReceive: SelectClause1<E>
158151

159152
/**
160153
* Retrieves and removes the element from this channel suspending the caller while this channel [isEmpty]
161-
* or returns `null` if the channel is [closed][isClosedForReceive] _normally_,
154+
* or returns `null` if the channel is [closed][isClosedForReceive] without cause
162155
* or throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
163156
*
164157
* This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this
@@ -181,21 +174,21 @@ public interface ReceiveChannel<out E> {
181174
/**
182175
* Clause for [select] expression of [receiveOrNull] suspending function that selects with the element that
183176
* is received from the channel or selects with `null` if if the channel
184-
* [isClosedForReceive][ReceiveChannel.isClosedForReceive] _normally_. The [select] invocation fails with
177+
* [isClosedForReceive] without cause. The [select] invocation fails with
185178
* the original [close][SendChannel.close] cause exception if the channel has _failed_.
186179
*/
187180
public val onReceiveOrNull: SelectClause1<E?>
188181

189182
/**
190-
* Retrieves and removes the head of this queue, or returns `null` if this queue [isEmpty]
191-
* or is [closed][isClosedForReceive] _normally_,
192-
* or throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
183+
* Retrieves and removes the element from this channel, or returns `null` if this channel [isEmpty]
184+
* or is [isClosedForReceive] without cause.
185+
* It throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
193186
*/
194187
public fun poll(): E?
195188

196189
/**
197190
* Returns new iterator to receive elements from this channels using `for` loop.
198-
* Iteration completes normally when the channel is [closed][isClosedForReceive] _normally_ and
191+
* Iteration completes normally when the channel is [isClosedForReceive] without cause and
199192
* throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
200193
*/
201194
public operator fun iterator(): ChannelIterator<E>
@@ -209,7 +202,7 @@ public interface ChannelIterator<out E> {
209202
/**
210203
* Returns `true` if the channel has more elements suspending the caller while this channel
211204
* [isEmpty][ReceiveChannel.isEmpty] or returns `false` if the channel
212-
* [isClosedForReceive][ReceiveChannel.isClosedForReceive] _normally_.
205+
* [isClosedForReceive][ReceiveChannel.isClosedForReceive] without cause.
213206
* It throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
214207
*
215208
* This function retrieves and removes the element from this channel for the subsequent invocation
@@ -232,7 +225,7 @@ public interface ChannelIterator<out E> {
232225
/**
233226
* Retrieves and removes the element from this channel suspending the caller while this channel
234227
* [isEmpty][ReceiveChannel.isEmpty] or throws [ClosedReceiveChannelException] if the channel
235-
* [isClosedForReceive][ReceiveChannel.isClosedForReceive].
228+
* [isClosedForReceive][ReceiveChannel.isClosedForReceive] without cause.
236229
* It throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
237230
*
238231
* This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this
@@ -308,14 +301,14 @@ public fun <E> Channel(capacity: Int): Channel<E> =
308301

309302
/**
310303
* Indicates attempt to [send][SendChannel.send] on [isClosedForSend][SendChannel.isClosedForSend] channel
311-
* that was closed _normally_. A _failed_ channel rethrows the original [close][SendChannel.close] cause
304+
* that was closed without a cause. A _failed_ channel rethrows the original [close][SendChannel.close] cause
312305
* exception on send attempts.
313306
*/
314307
public class ClosedSendChannelException(message: String?) : CancellationException(message)
315308

316309
/**
317310
* Indicates attempt to [receive][ReceiveChannel.receive] on [isClosedForReceive][ReceiveChannel.isClosedForReceive]
318-
* channel that was closed _normally_. A _failed_ channel rethrows the original [close][SendChannel.close] cause
311+
* channel that was closed without a cause. A _failed_ channel rethrows the original [close][SendChannel.close] cause
319312
* exception on receive attempts.
320313
*/
321314
public class ClosedReceiveChannelException(message: String?) : NoSuchElementException(message)

core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/channels/ConflatedBroadcastChannel.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public class ConflatedBroadcastChannel<E>() : BroadcastChannel<E> {
7777
* The most recently sent element to this channel.
7878
*
7979
* Access to this property throws [IllegalStateException] when this class is constructed without
80-
* initial value and no value was sent yet or if it was [closed][close] _normally_ and
81-
* throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
80+
* initial value and no value was sent yet or if it was [closed][close] without a cause.
81+
* It throws the original [close][SendChannel.close] cause exception if the channel has _failed_.
8282
*/
8383
@Suppress("UNCHECKED_CAST")
8484
public val value: E get() {
@@ -187,9 +187,7 @@ public class ConflatedBroadcastChannel<E>() : BroadcastChannel<E> {
187187
/**
188188
* Sends the value to all subscribed receives and stores this value as the most recent state for
189189
* future subscribers. This implementation never suspends.
190-
*
191-
* It throws [ClosedSendChannelException] if the channel [isClosedForSend] _normally_.
192-
* It throws the original [close] cause exception if the channel has _failed_.
190+
* It throws exception if the channel [isClosedForSend] (see [close] for details).
193191
*/
194192
suspend override fun send(element: E) {
195193
offerInternal(element)?.let { throw it.sendException }
@@ -198,9 +196,7 @@ public class ConflatedBroadcastChannel<E>() : BroadcastChannel<E> {
198196
/**
199197
* Sends the value to all subscribed receives and stores this value as the most recent state for
200198
* future subscribers. This implementation always returns `true`.
201-
*
202-
* It throws [ClosedSendChannelException] if the channel [isClosedForSend] _normally_.
203-
* It throws the original [close] cause exception if the channel has _failed_.
199+
* It throws exception if the channel [isClosedForSend] (see [close] for details).
204200
*/
205201
override fun offer(element: E): Boolean {
206202
offerInternal(element)?.let { throw it.sendException }

0 commit comments

Comments
 (0)