send

abstract suspend fun send(element: E): Unit (source)

Adds element into to this channel, suspending the caller while this channel isFull, or throws exception if the channel isClosedForSend (see close for details).

Note, that closing a channel after this function had suspended does not cause this suspended send invocation to abort, because closing a channel is conceptually like sending a special “close token” over this channel. All elements that are sent over the channel are delivered in first-in first-out order. The element that is being sent will get delivered to receivers before a close token.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with CancellationException.

Cancellation of suspended send is atomic – when this function throws CancellationException it means that the element was not sent to this channel. As a side-effect of atomic cancellation, a thread-bound coroutine (to some UI thread, for example) may continue to execute even after it was cancelled from the same thread in the case when this send operation was already resumed and the continuation was posted for execution to the thread’s queue.

Note, that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.

This function can be used in select invocation with onSend clause. Use offer to try sending to this channel without waiting.