subscribe

abstract fun subscribe(subscriber: Any)

Registers all instance methods on subscriber annotated with @Subscribe.

Methods handling event types outside E are silently ignored at dispatch time. Calling this with the same object more than once is idempotent.


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

Registers a lambda handler for event type T and returns a Subscription token.

Kotlin callers should prefer the reified inline overload:

val sub = networkBus.subscribe<PacketReceived>(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 <T : E> subscribe(eventClass: Class<T>, priority: Int, handler: (T) -> Unit): Subscription

Registers a lambda handler for event type T 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 : E> subscribe(eventClass: Class<T>, priority: Int, async: Boolean, handler: Consumer<T>): Subscription

Registers a Consumer handler for event type T and returns a Subscription token.

Java callers use plain void lambdas:

networkBus.subscribe(PacketReceived.class, Priority.NORMAL, true, e -> handle(e.bytes));

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 : E> subscribe(eventClass: Class<T>, priority: Int, handler: Consumer<T>): Subscription

Registers a Consumer handler for event type T with synchronous dispatch.

Preserves binary compatibility with callers that predate the async parameter.

Return

a Subscription whose Subscription.cancel removes this handler.