send
Sends the specified element to this channel, suspending the caller while the buffer of this channel is full or if it does not exist, or throws an exception if the channel is closed for send
(see close for details).
Closing a channel after this function has 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 sent over the channel are delivered in first-in first-out order. The sent element will be delivered to receivers before the close token.
This suspending function is cancellable: if the Job of the current coroutine is cancelled while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee: even if send managed to send the element, but was cancelled while suspended, CancellationException will be thrown. See suspendCancellableCoroutine for low-level details.
Because of the prompt cancellation guarantee, an exception does not always mean a failure to deliver the element. See "Undelivered elements" section in Channel documentation for details on handling undelivered elements.
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 invocations with the onSend clause. Use trySend to try sending to this channel without waiting.