MessageHandler

class MessageHandler<T : Any>(messageBus: MessageBus, scope: CoroutineScope, topic: Topic<T>, handleError: suspend (Throwable) -> Unit = {}, handleMessage: suspend (message: T) -> Unit) : FusComponent

A handler for subscribing to a specific message topic on a MessageBus. It listens for messages published to the specified Topic and processes them using the provided handler function on a new coroutine in the provided CoroutineScope.

Be careful when using shared resources in the handleMessage function. It may run concurrently.

Parameters

messageBus

The MessageBus instance the handler subscribes to.

scope

The CoroutineScope in which the handler operates.

topic

The Topic that the handler subscribes to for receiving messages.

handleError

Function for handling errors that occur during execution of handleMessage. Errors do not cause the flow to complete.

handleMessage

A suspending function invoked for each received message associated with the given topic.

Type Parameters

T

The type of messages to handle, constrained to non-nullable types.

Constructors

Link copied to clipboard
constructor(messageBus: MessageBus, scope: CoroutineScope, topic: Topic<T>, handleError: suspend (Throwable) -> Unit = {}, handleMessage: suspend (message: T) -> Unit)

Properties

Link copied to clipboard
val job: Job

Functions

Link copied to clipboard
open suspend override fun close()

Called when FusClient is closed.