EventHandler

@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class EventHandler(val priority: Int = 0, val runIfCanceled: Boolean = false)

Marks a function as an event handler that should be invoked when an event of the appropriate type is posted to a Bus.

A valid event handler method must:

  • Be annotated with EventHandler.

  • Accept exactly one parameter whose type implements Event.

  • Have a void/Unit return type.

Handlers may be:

Invocation Order

When an event is posted, all matching handlers are invoked in order of descending priority. Handlers with the same priority execute in registration order.

Cancellation Interaction

If the event implements Cancelable, delivery of the event to this handler is influenced by:

  1. The EventHandler.runIfCanceled flag, and

  2. The CancelMode supplied to Bus.post.

runIfCanceled

When true, this handler will still receive the event even if it has been canceled — unless the dispatch mode is CancelMode.ENFORCE, in which case no additional handlers run after cancellation.

When false (default), this handler:

  • receives the event normally when it is not canceled,

  • receives the event only if the current CancelMode is:

    • CancelMode.IGNORE, or

    • CancelMode.RESPECT and the event is not canceled.

Properties

Link copied to clipboard
val priority: Int = 0

Determines the execution order when multiple handlers receive the same event. Higher values run earlier.

Link copied to clipboard
val runIfCanceled: Boolean = false

Whether this handler should receive events that have already been marked as canceled.