interface EventChannel<E : Any>Helper for Reactors that can accept events from external sources.
From inside onReact, you can handle events by calling select and passing a block that describes
how to handle each event type you're willing to accept. A Single will be returned that will
complete as soon as a matching event (or other clause, see below) is selected. Any exceptions
thrown from within your event handler blocks, or the select block itself, will be reported
through that Single.
For example,
events.select {
onEvent<ButtonClicked> { EnterState(ButtonHasBeenClicked) }
onEvent<BackPressed> { FinishWith(Canceled) }
}
You can also simultaneously wait for Singles to complete by calling onSuccess alongside your
onEvents.
When you specify at least one onEvent clause, if the next event sent down the channel doesn't
match any of your clauses, the Single will complete with an IllegalStateException.
If, at the time an event is sent, the reactor is not actively listening for events, the event will be queued up and delivered as soon as the reactor asks for the next event. Note that when the reactor does get around to processing the next event, if it doesn't match any of its cases, it will still throw. Events are not re-ordered or re-enqueued to try to find a matching event.
E - The supertype of all valid events. Probably a sealed class.
select |
abstract fun <R : Any> select(block: EventSelectBuilder<E, R>.() -> Unit): Single<out R> |