EventSource
Value members
Abstract methods
Creates a Subscription to a function which will consume events in the given ExecutionContext
.
In simpler terms: A subscriber is a function which will receive events from the event source. For every event,
the function will be executed in the given execution context - not necessarily the same as the one used for
emitting the event. This allows for easy communication between parts of the program working in different
execution contexts, e.g. the user interface and the database.
Creates a Subscription to a function which will consume events in the given ExecutionContext
.
In simpler terms: A subscriber is a function which will receive events from the event source. For every event,
the function will be executed in the given execution context - not necessarily the same as the one used for
emitting the event. This allows for easy communication between parts of the program working in different
execution contexts, e.g. the user interface and the database.
The Subscription will be automatically enabled (Subscription.enable).
- Value Params
- body
A function which consumes the event
- ec
An
ExecutionContext
in which the given function will be executed.- eventContext
An EventContext which will register the Subscription for further management (optional)
- Returns
A Subscription representing the created connection between the event source and the body function.
Creates a Subscription to a function which will consume events in the same ExecutionContext
as
the one in which the events are being emitted.
Creates a Subscription to a function which will consume events in the same ExecutionContext
as
the one in which the events are being emitted.
- Value Params
- body
A function which consumes the event
- eventContext
an EventContext which will register the Subscription for further management (optional)
- Returns
a Subscription representing the created connection between the EventSource and the body function
- See also
EventSource.on The Subscription will be automatically enabled (Subscription.enable).
This method will be called on removing the last subscription if disableAutoWiring
was not called.
This method will be called on removing the last subscription if disableAutoWiring
was not called.
This method will be called on creating the first subscription or on disableAutoWiring
.
If the implementing class stashes intermediate computation, this should trigger their execution.
This method will be called on creating the first subscription or on disableAutoWiring
.
If the implementing class stashes intermediate computation, this should trigger their execution.
Concrete methods
Typically, a newly created event streams and signals are lazy in the sense that till there are no subscriptions to them,
they will not execute any intermediate computations (e.g. assembled to it through maps, flatMaps, etc). After all,
those computations would be ignored at the end. Only when a subscription is created, the computations are performed
for the first time.
disableAutowiring
enforces those computations even if there are no subscribers. It can be useful if e.g. the computations
perform side-effects or if it's important from the performance point of view to have the intermediate results ready
when the subscriber is created.
Typically, a newly created event streams and signals are lazy in the sense that till there are no subscriptions to them,
they will not execute any intermediate computations (e.g. assembled to it through maps, flatMaps, etc). After all,
those computations would be ignored at the end. Only when a subscription is created, the computations are performed
for the first time.
disableAutowiring
enforces those computations even if there are no subscribers. It can be useful if e.g. the computations
perform side-effects or if it's important from the performance point of view to have the intermediate results ready
when the subscriber is created.
- Returns
The current instance, so that
disableAutoworing
can be chained with other method calls.
An alias for the on
method with the default ExecutionContext.
An alias for the on
method with the default ExecutionContext.
Checks if there are any subscribers registered in this EventRelay
.
Checks if there are any subscribers registered in this EventRelay
.
- Returns
true if any subscribers are registered, false otherwise
The class which implements this EventRelay
can use this method to notify all the subscribers that a new event
arrived.
The class which implements this EventRelay
can use this method to notify all the subscribers that a new event
arrived.
- Value Params
- call
A function that will perform some action on each subscriber
Adds a new subscriber instance. The implementing class should handle notifying this subscriber
when a new event arrives. If this is the first subscriber, and disableAutowiring
wasn't called previous,
this will trigger a call to onWire
.
Adds a new subscriber instance. The implementing class should handle notifying this subscriber
when a new event arrives. If this is the first subscriber, and disableAutowiring
wasn't called previous,
this will trigger a call to onWire
.
- Value Params
- subscriber
An instance of a subscriber class, known to the class implementing this
EventRelay
Removes a previously registered subscriber instance.
If this is the last subscriber, and disableAutowiring
wasn't called previously, this will trigger a call to onUnwire
.
Removes a previously registered subscriber instance.
If this is the last subscriber, and disableAutowiring
wasn't called previously, this will trigger a call to onUnwire
.
- Value Params
- subscriber
An instance of a subscriber class, known to the class implementing this
EventRelay