subscribe

abstract fun subscribe(subscriber: Any)

Registers all instance methods on subscriber annotated with @Subscribe.

Calling this with the same object more than once is idempotent; already-registered handlers are not duplicated.


abstract fun subscribe(eventClass: Class<out Event>, priority: Int, async: Boolean, handler: (Event) -> Unit): Subscription

Registers a lambda handler for eventClass and returns a Subscription token.

Kotlin callers should prefer the reified inline overload:

val sub = bus.subscribe<MyEvent>(async = true) { e -> handle(e) }

Return

a Subscription whose Subscription.cancel removes this handler.

Parameters

async

If true, dispatches on the bus's executor; falls back to sync if none configured.


open fun subscribe(eventClass: Class<out Event>, priority: Int, handler: (Event) -> Unit): Subscription

Registers a lambda handler for eventClass with synchronous dispatch.

Preserves binary compatibility with callers that predate the async parameter.

Return

a Subscription whose Subscription.cancel removes this handler.


open fun <T : Event> subscribe(eventClass: Class<T>, priority: Int, async: Boolean, handler: Consumer<T>): Subscription

Registers a Consumer handler for eventClass and returns a Subscription token.

Java callers use plain void lambdas:

Subscription sub = bus.subscribe(MyEvent.class, Priority.NORMAL, true, e -> handle(e));

Return

a Subscription whose Subscription.cancel removes this handler.

Parameters

async

If true, dispatches on the bus's executor; falls back to sync if none configured.


open fun <T : Event> subscribe(eventClass: Class<T>, priority: Int, handler: Consumer<T>): Subscription

Registers a Consumer handler for eventClass with synchronous dispatch.

Preserves binary compatibility with callers that predate the async parameter.

Return

a Subscription whose Subscription.cancel removes this handler.