ChannelMessageSubscriptionHandler

class ChannelMessageSubscriptionHandler(signaldClient: SignaldClient, coroutineScope: CoroutineScope, context: CoroutineContext, bufferCapacity: Int, onBufferOverflow: BufferOverflow, onUndeliveredElement: (ClientMessageWrapper) -> Unit?) : CoroutineMessageSubscriptionHandler

Creates a Channel-based message handler. Messages can be received by receiving elements from the messages. Unsubscription and closing of the socket is handled by calling close or cancelling the given coroutineScope.

Parameters

signaldClient

The SignaldClient instance. Must be associated with an account registered with signald.

coroutineScope

The CoroutineScope to use for the message subscription coroutine.

context

An additional CoroutineContext that will be added to the given coroutineScope's context.

bufferCapacity

Size of the buffer for the channel. (optional, cannot be negative, defaults to Channel.RENDEZVOUS, i.e. zero). This option should be used with care; setting a higher buffer means that the client will take messages from signald that will be buffered locally, but if the client crashes and never handles those messages, signald will not resend those messages.

onBufferOverflow

configures an action on buffer overflow (optional, defaults to a suspending attempt to send a value, supported only when capacity >= 0 or capacity == Channel.BUFFERED, implicitly creates a channel with at least one buffered element)

onUndeliveredElement

An optional function that is called when element was sent but was not delivered to the consumer. See "Undelivered elements" section in Channel documentation.

Throws

if subscription fails (e.g., creating the persistent socket fails)

Constructors

Link copied to clipboard
fun ChannelMessageSubscriptionHandler(signaldClient: SignaldClient, coroutineScope: CoroutineScope, context: CoroutineContext = EmptyCoroutineContext, bufferCapacity: Int = Channel.RENDEZVOUS, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, onUndeliveredElement: (ClientMessageWrapper) -> Unit? = null)

Functions

Link copied to clipboard
open override fun close()

Properties

Link copied to clipboard
val messages: ReceiveChannel<ClientMessageWrapper>

A ReceiveChannel of incoming messages. As ClientMessageWrapper is a sealed type, using a when statement on the message will be exhaustive.