cancel

abstract fun cancel(
    cause: CancellationException? = null
): Unit
(source)

Cancels reception of remaining elements from this channel with an optional cause. This function closes the channel and removes all buffered sent elements from it.

A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes. If the cause is not specified, then an instance of CancellationException with a default message is created to close the channel.

Immediately after invocation of this function isClosedForReceive and isClosedForSend on the side of SendChannel start returning true. All attempts to send to this channel or receive from this channel will throw CancellationException.