nextEventOrNull

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

Suspends until the next event of type T matching predicate is posted, or until timeout elapses, whichever comes first.

Returns null if the timeout elapses before a matching event arrives.

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

Parameters

timeout

Maximum duration to wait for a matching event.

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>.nextEventOrNull(timeout: Duration, 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, or until timeout elapses.

Returns null if the timeout elapses before a matching event arrives.

Parameters

timeout

Maximum duration to wait for a matching event.

priority

Dispatch priority; defaults to Priority.NORMAL.

predicate

Filter applied to incoming events; defaults to always true.