Skip to content

Stabilize isClosedForSend and isClosedForReceive #3517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 16, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions kotlinx-coroutines-core/common/src/channels/Channel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import kotlin.jvm.*
*/
public interface SendChannel<in E> {
/**
* Returns `true` if this channel was closed by an invocation of [close]. This means that
* calling [send] will result in an exception.
* Returns `true` if this channel was closed by an invocation of [close] or its receiving side was [cancelled][ReceiveChannel.cancel].
* This means that calling [send] will result in an exception.
*
* **Note: This is an experimental api.** This property may change its semantics and/or name in the future.
* Note that if this property returns `false`, it does not guarantee that consecutive call to [send] will succeed, as the
* channel can be concurrently closed right after the check. For such scenarios, it is recommended to use [trySend] instead.
*
* @see SendChannel.close
* @see ReceiveChannel.cancel
*/
@ExperimentalCoroutinesApi
public val isClosedForSend: Boolean

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

/**
Expand Down