nextEvent

inline suspend fun <T : Event> EventBus.nextEvent(priority: Int = Priority.NORMAL, crossinline predicate: (T) -> Boolean = { true }): T

Suspends until the next event of type T matching predicate is posted, then resumes with that event.

The handler is registered synchronously inside the coroutine body before the first suspension point. In a kotlinx.coroutines.runBlocking + kotlinx.coroutines.launch context, use kotlinx.coroutines.Dispatchers.Unconfined to ensure the coroutine body executes and registers the subscription before any event is posted. In a real coroutine scope that is already running, no special dispatcher is needed.

val packet = bus.nextEvent<PacketReceived>()
val packet = bus.nextEvent<PacketReceived> { it.bytes.size > 100 }

Parameters

priority

Dispatch priority; defaults to Priority.NORMAL.

predicate

Filter applied to incoming events; defaults to always true.


inline suspend fun <T : Event> TypedEventBus<in T>.nextEvent(priority: Int = Priority.NORMAL, crossinline predicate: (T) -> Boolean = { true }): T

Suspends until the next event of type T matching predicate is posted on this TypedEventBus, then resumes with that event.

Parameters

priority

Dispatch priority; defaults to Priority.NORMAL.

predicate

Filter applied to incoming events; defaults to always true.