Package discord4j.core.event
Class SinksEventDispatcher
java.lang.Object
discord4j.core.event.SinksEventDispatcher
- All Implemented Interfaces:
EventDispatcher
-
Nested Class Summary
-
Field Summary
Fields inherited from interface discord4j.core.event.EventDispatcher
DEFAULT_EVENT_SCHEDULER
-
Constructor Summary
ConstructorDescriptionSinksEventDispatcher
(Function<Sinks.ManySpec, Sinks.Many<Event>> eventSinkFactory, EmissionStrategy emissionStrategy, Scheduler eventScheduler) Creates a new event dispatcher using the given event sink factory and threading model. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface discord4j.core.event.EventDispatcher
on, on
-
Constructor Details
-
SinksEventDispatcher
public SinksEventDispatcher(Function<Sinks.ManySpec, Sinks.Many<Event>> eventSinkFactory, EmissionStrategy emissionStrategy, Scheduler eventScheduler) Creates a new event dispatcher using the given event sink factory and threading model.- Parameters:
eventSinkFactory
- the custom sink factory for eventsemissionStrategy
- a strategy to handle emission failureseventScheduler
- aScheduler
to ensure a certain thread model on each published signal
-
-
Method Details
-
on
Description copied from interface:EventDispatcher
Retrieves aFlux
with elements of the givenEvent
type. ThisFlux
has to be subscribed to in order to start processing. SeeEvent
class for the list of possible event classes.Note: Errors occurring while processing events will terminate your sequence. If you wish to use a version capable of handling errors for you, use
EventDispatcher.on(Class, Function)
. See Reactive Streams Spec explaining this behavior.A recommended pattern to use this method is wrapping your code that may throw exceptions within a
flatMap
block and useMono.onErrorResume(Function)
,Flux.onErrorResume(Function)
or equivalent methods to maintain the sequence active:client.getEventDispatcher().on(MessageCreateEvent.class) .flatMap(event -> myCodeThatMightThrow(event) .onErrorResume(error -> { // log and then discard the error to keep the sequence alive log.error("Failed to handle event!", error); return Mono.empty(); })) .subscribe();
For more alternatives to handling errors, please see Error Handling docs page.
- Specified by:
on
in interfaceEventDispatcher
- Type Parameters:
E
- the type of the event class- Parameters:
eventClass
- the event class to obtain events from- Returns:
- a new
Flux
with the requested events
-
publish
Description copied from interface:EventDispatcher
Publishes anEvent
to the dispatcher. Might throw an unchecked exception if the dispatcher can't handle this event.- Specified by:
publish
in interfaceEventDispatcher
- Parameters:
event
- theEvent
to publish
-
shutdown
public void shutdown()Description copied from interface:EventDispatcher
Signal that this event dispatcher must terminate and release its resources.- Specified by:
shutdown
in interfaceEventDispatcher
-