abstract fun cancel(cause: Throwable? = null): Boolean

Cancels reception of remaining elements from this channel. This function closes the channel with the specified cause (unless it was already closed) and removes all buffered sent elements from it. This function returns true if the channel was not closed previously, or false otherwise.

Immediately after invocation of this function isClosedForReceive and isClosedForSend on the side of SendChannel start returning true, so all attempts to send to this channel afterwards will throw ClosedSendChannelException, while attempts to receive will throw ClosedReceiveChannelException if it was cancelled without a cause. A channel that was cancelled with non-null cause is called a failed channel. Attempts to send or receive on a failed channel throw the specified cause exception.