signalMessagesChannel

fun CoroutineScope.signalMessagesChannel(signaldClient: SignaldClient, context: CoroutineContext = EmptyCoroutineContext, bufferCapacity: Int = Channel.RENDEZVOUS, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND, onUndeliveredElement: (ClientMessageWrapper) -> Unit? = null): ReceiveChannel<ClientMessageWrapper>

Launches a new coroutine that uses the signaldClient to create a new socket connection and using the socket to subscribe to incoming messages from signald. The incoming messages are sent through the returned ReceiveChannel.

The coroutine context is inherited from a CoroutineScope. Additional context elements can be specified with the context parameter.

Cancellation of the scope or cancelling the channel will unsubscribe from incoming messages and close the socket.

It's recommended that this function is called from a coroutine context that can handle blocking IO calls such as Dispatchers.IO on JVM or using a new single-threaded context.

See also

Parameters

signaldClient

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

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)