Skip to main content
Klyx provides an EventBus architecture for decoupled communication between plugins and the host application. Events are typed, support priority ordering, flow-based collection, and sticky events.

Accessing the EventBus

The EventBus is accessible through PluginContext:

Subscribing to events

Use the subscribe method with the event type and a handler lambda:

Subscription options

Subscription return value

subscribe returns an EventSubscription handle with a cancel() method:

Collecting as a Flow

Events can also be observed as a cold Flow:

Waiting for a single event

Event priority

All subscriptions have a Priority level. Higher priority subscribers receive events first:

Sticky events

Sticky events are retained by the bus and immediately delivered to new subscribers. Sticky events are configured when creating the bus via EventBusConfigBuilder.

Managing sticky events

Common event types

FileOpenedEvent

EventBus methods

Lifecycle

Event subscriptions remain active until explicitly cancelled or the bus is closed. For lifecycle-aware usage, tie subscriptions to a coroutine scope:

Publishing events

Plugins can publish their own events:

Example

Subscribe to file open events and react to them: