close

open fun close(cause: Throwable?): Boolean (source)

Overrides SendChannel.close

Platform and version requirements: JVM

Closes this channel with an optional exceptional cause. This is an idempotent operation – repeated invocations of this function have no effect and return false. Conceptually, its sends a special “close token” over this channel.

Immediately after invocation of this function isClosedForSend starts returning true. However, isClosedForReceive on the side of ReceiveChannel starts returning true only after all previously sent elements are received.

A channel that was closed without a cause throws ClosedSendChannelException on attempts to send or receive. A channel that was closed with non-null cause is called a failed channel. Attempts to send or receive on a failed channel throw the specified cause exception.