Title: Theory / Unimportant / CS / Programming / Kotlin / Library / Channel
Tags: automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Language: Kotlin

Typ: Channel<T>
Meaning: An object that allow to send values of type T from and to coroutines
Page: https://kotlinlang.org/docs/channels.html#channel-basics
Language: Kotlin
Subtype of: SendChannel<E>, ReceiveChannel<E>

Instruction: channel.send(t)
Page: https://kotlinlang.org/docs/channels.html
Effect: add t to channel. Block if it can't accept more values now
Variables: Channel<T> channel

Instruction: receiveChannel.receive()
Page: https://kotlinlang.org/docs/channels.html
Effect: Block until one is available.
Returns: A value added to the channel.
Variables: ReceiveChannel<T> receiveChannel

Instruction: senderChannel.close()
Page: https://kotlinlang.org/docs/channels.html
Effect: Close the channel. Indicates to listener there won't be more messages
Returns: A value added to the channel. Block until one is available.
Variables: SenderChannel<T> senderChannel

Instruction: receiveChannel.consumeEach(fn)
Page: https://kotlinlang.org/docs/channels.html
Effect: apply fn to each element emitted by receiveChannel
Returns: A value added to the channel. Block until one is available.
Variables: ReceiveChannel<T> receiveChannel

Name: A pipeline
Definition: a pattern where one coroutine is producing, possibly infinite, stream of values
Page: https://kotlinlang.org/docs/channels.html

Instruction: produce<T> {foo}
Page: https://kotlinlang.org/docs/channels.html
Returns: A ReceiveChannel that receive values emitted by foo

Instruction: Channel<T>(
  capacity,
  onBufferOverflow,
  onUndeliveredElement
)
Page: https://kotlinlang.org/docs/channels.html
Returns: A new channel of type T with buffer for capacity elements.
Calling onUndeliveredElement(  element) on element that can't be delivered

Typ: Ticker
Meaning: A ReceiveChannel<Unit> that sends a message at regular interval
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin

Instruction: ticker(
  delayMillis,
  initialDelayMillis
)
Page: https://kotlinlang.org/docs/channels.html
Returns: A Ticker that outputs every delayMillis, starting atfter initialDelayMillis
Typ: Tick

Instruction: actor
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/actor.html
Effect: todo

Typ: ProducerScope<in E>
Meaning: Scope for the produce, callbackFlow and channelFlow builders.
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/actor.html
Language: Kotlin
Subtype of: CoroutineScope, SendChannel<E>

Variable: producerScope.channel
Meaning: A reference to the channel this coroutine sends elements to
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/actor.html
Language: Kotlin
Variables: ProducerScope<in E> producerScope
Extra: It is provided for convenience, so that the code in the coroutine can refer to the channel as channel as opposed to this

Name: A rendez-vous channel
Definition: A channel without buffer, when message are sent and received at the same time
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html
Variables: ProducerScope<in E> producerScope

Typ: ChannelIterator<out E>
Meaning: Iterator for ReceiveChannel
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html
Language: Kotlin

Typ: ChannelResult<out T>
Meaning: A discriminated union of channel operation result.
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html
Language: Kotlin

Typ: ClosedReceiveChannelException
Meaning: Indicates an attempt to receive from a isClosedForReceive channel that was closed without a cause.
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html
Language: Kotlin
Subtype of: NoSuchElementException

Typ: ClosedSendChannelException
Meaning: Indicates an attempt to send to a isClosedForSend channel that was closed without a cause.
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html
Language: Kotlin
Subtype of: IllegalStateException

Typ: ReceiveChannel<out E>
Meaning: Receiver's interface to Channel.
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html
Language: Kotlin

Typ: SendChannel<in E>
Meaning: Sender interface to Channel.
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html
Language: Kotlin

Instruction: receiveChannel.toList(fn)
Page: https://kotlinlang.org/docs/channels.html
Returns: a List containing all elements.
Variables: ReceiveChannel<T> receiveChannel

Instruction: channelResult.getOrElse(onFailure)
Page: https://kotlinlang.org/docs/channels.html
Returns: the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failed or closed result.
Variables: ChannelResult<T> channelResult

Instruction: channelResult.onClosed(action)
Page: https://kotlinlang.org/docs/channels.html
Effect: Performs the given action on the encapsulated Throwable exception if this instance represents failure due to channel being closed.
Returns: the original ChannelResult unchanged.
Variables: ChannelResult<T> channelResult
Extra: The result of ChannelResult.exceptionOrNull is passed to the action parameter. It is guaranteed that if action is invoked, then the channel is either closed for send or is closed for receive depending on the failed operation.

Instruction: channelResult.onFailure(action)
Page: https://kotlinlang.org/docs/channels.html
Effect: Performs the given action on the encapsulated Throwable exception if this instance represents failure.
Returns: the original ChannelResult unchanged.
Variables: ChannelResult<T> channelResult

Instruction: channelResult.onSuccess(action)
Page: https://kotlinlang.org/docs/channels.html
Effect: Performs the given action on the encapsulated value if this instance represents success.
Returns: the original ChannelResult unchanged.
Variables: ChannelResult<T> channelResult

Instruction: producerScope.awaitClose(block)
Page: https://kotlinlang.org/docs/channels.html
Effect: Suspends the current coroutine until the channel is either closed or cancelled and invokes block before resuming the coroutine.
Variables: ProducerScope producerScope

Instruction: sendChannel.trySendBlocking(element)
Page: https://kotlinlang.org/docs/channels.html
Effect: Adds element to this channel, blocking the caller while this channel is full
Returns: ChannelResult of the success of this operation
Variables: SendChannel sendChannel
Where to use it: outside of coroutine

Instruction: sendChannel.invokeOnClose(handler)
Page: https://kotlinlang.org/docs/channels.html
Effect: Registers a handler which is synchronously invoked once the channel is closed or the receiving side of this channel is cancelled.
Variables: SendChannel sendChannel

Instruction: sendChannel.trySend(element)
Page: https://kotlinlang.org/docs/channels.html
Effect: Immediately adds the specified element to this channel, if this doesn't violate its capacity restrictions. Don't block
Returns: ChannelResult of the success of this operation
Variables: SendChannel sendChannel
Where to use it: outside of coroutine

Instruction: receiveChannel.cancel(cause = null)
Page: https://kotlinlang.org/docs/channels.html
Effect: cancel the channel due to cause
Returns: ChannelResult of the success of this operation
Variables: ReceiveChannel receiveChannel
Where to use it: outside of coroutine

Instruction: receiveChannel.iterator()
Page: https://kotlinlang.org/docs/channels.html
Effect: a new iterator to receive elements from this channel using a for loop
Returns: ChannelResult of the success of this operation
Variables: ReceiveChannel receiveChannel
Where to use it: outside of coroutine

Instruction: receiveChannel.tryReceive()
Page: https://kotlinlang.org/docs/channels.html
Returns: A channel result with an element of the chan, or failure
Variables: ReceiveChannel receiveChannel

Variable: receiveChannel.isClosedForReceive
Meaning: Experimental: whether channel is closed and all has been received
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin
Variables: ReceiveChannel receiveChannel

Variable: receiveChannel.isEmpty
Meaning: Experimental: whether channel is currently empty and not closed
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin
Variables: ReceiveChannel receiveChannel

Variable: receiveChannel.onReceive
Meaning: Clause for the select expression of the receive suspending function that selects with the element received from the channel.
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin
Variables: ReceiveChannel receiveChannel

Variable: receiveChannel.onReceiveCatching
Meaning: Clause for the select expression of the onReceiveCatching suspending function that selects with the ChannelResult with a value that is received from the channel or with a close cause if the channel is closed for receive.
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin
Variables: ReceiveChannel receiveChannel

Variable: senderChannel.onSend
Meaning: Clause for the select expression of the send suspending function that selects when the element that is specified as the parameter is sent to the channel. When the clause is selected, the reference to this channel is passed into the corresponding block.
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin
Variables: SenderChannel senderChannel

Instruction: channelResult.exceptionOrNull()
Page: https://kotlinlang.org/docs/channels.html
Returns: the encapsulated exception if this instance represents failure or null if it is success or unsuccessful operation to closed channel.
Variables: ChannelResult channelResult

Instruction: channelResult.getOrNull()
Page: https://kotlinlang.org/docs/channels.html
Returns: the encapsulated value if this instance represents success or throws an exception if it is closed or failed.
Variables: ChannelResult channelResult

Variable: channelResult.isClosed
Meaning: this instance represents unsuccessful operation to a closed or cancelled channel.
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin
Variables: ChannelResult channelResult

Variable: channelResult.isFailure
Meaning: Whether this instance represents unsuccessful operation.
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin
Variables: ChannelResult channelResult

Variable: channelResult.isSuccess
Meaning: this instance represents a successful operation outcome.
Page: https://kotlinlang.org/docs/channels.html
Language: Kotlin
Variables: ChannelResult channelResult

Instruction: produce
Page: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.channels/produce.html
Effect: todo: experimeental
Variables: ChannelResult channelResult

Instruction: supervisorScope(fn)
Page: https://kotlinlang.org/docs/exception-handling.html#supervision-scope
Effect: Execute fn in a coroutine where cancelling only go to children but not to parents. Exception don't propagate to parent