Skip to content

Commit 9ae476f

Browse files
authored
Stabilize isClosedForSend and isClosedForReceive (#3517)
* Stabilize isClosedForSend and isClosedForReceive Fixes #3448
1 parent 30e905c commit 9ae476f

File tree

1 file changed

+21
-10
lines changed
  • kotlinx-coroutines-core/common/src/channels

1 file changed

+21
-10
lines changed

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

+21-10
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ import kotlin.jvm.*
2323
*/
2424
public interface SendChannel<in E> {
2525
/**
26-
* Returns `true` if this channel was closed by an invocation of [close]. This means that
27-
* calling [send] will result in an exception.
26+
* Returns `true` if this channel was closed by an invocation of [close] or its receiving side was [cancelled][ReceiveChannel.cancel].
27+
* This means that calling [send] will result in an exception.
2828
*
29-
* **Note: This is an experimental api.** This property may change its semantics and/or name in the future.
29+
* Note that if this property returns `false`, it does not guarantee that consecutive call to [send] will succeed, as the
30+
* channel can be concurrently closed right after the check. For such scenarios, it is recommended to use [trySend] instead.
31+
*
32+
* @see SendChannel.trySend
33+
* @see SendChannel.close
34+
* @see ReceiveChannel.cancel
3035
*/
31-
@ExperimentalCoroutinesApi
36+
@DelicateCoroutinesApi
3237
public val isClosedForSend: Boolean
3338

3439
/**
@@ -174,14 +179,20 @@ public interface SendChannel<in E> {
174179
public interface ReceiveChannel<out E> {
175180
/**
176181
* Returns `true` if this channel was closed by invocation of [close][SendChannel.close] on the [SendChannel]
177-
* side and all previously sent items were already received. This means that calling [receive]
178-
* will result in a [ClosedReceiveChannelException]. If the channel was closed because of an exception, it
179-
* is considered closed, too, but is called a _failed_ channel. All suspending attempts to receive
180-
* an element from a failed channel throw the original [close][SendChannel.close] cause exception.
182+
* side and all previously sent items were already received, or if the receiving side was [cancelled][ReceiveChannel.cancel].
183+
*
184+
* This means that calling [receive] will result in a [ClosedReceiveChannelException] or a corresponding cancellation cause.
185+
* If the channel was closed because of an exception, it is considered closed, too, but is called a _failed_ channel.
186+
* All suspending attempts to receive an element from a failed channel throw the original [close][SendChannel.close] cause exception.
181187
*
182-
* **Note: This is an experimental api.** This property may change its semantics and/or name in the future.
188+
* Note that if this property returns `false`, it does not guarantee that consecutive call to [receive] will succeed, as the
189+
* channel can be concurrently closed right after the check. For such scenarios, it is recommended to use [receiveCatching] instead.
190+
*
191+
* @see ReceiveChannel.receiveCatching
192+
* @see ReceiveChannel.cancel
193+
* @see SendChannel.close
183194
*/
184-
@ExperimentalCoroutinesApi
195+
@DelicateCoroutinesApi
185196
public val isClosedForReceive: Boolean
186197

187198
/**

0 commit comments

Comments
 (0)