SourceStream
The usual entry point for publishing events.
The usual entry point for publishing events.
Create a new source stream either using the default constructor or the EventStream.apply[V]()
method. The source stream exposes
methods you can use for publishing new events. Then you can combine it with other event streams and finally subscribe a function
to it which will receive the resulting events.
- Type Params
- E
the type of the event
Value members
Concrete methods
An alias for the publish
method with no explicit execution context.
An alias for the publish
method with no explicit execution context.
A version of the publish
method which takes the implicit execution context for dispatching.
A version of the publish
method which takes the implicit execution context for dispatching.
The difference between !!
and !
(and also between the two publish
methods) is that even if the source's
execution context is the same as the subscriber's execution context, if we send an event using !
, it will be
wrapped in a future and executed asychronously. If we use !!
then for subscribers working in the same
execution context the call will be synchronous. This may be desirable in some cases, but please use with caution.
Publishes the event to all subscribers.
Publishes the event to all subscribers.
- Value Params
- event
The event to be published.
- See also
EventStream.publish The original
publish
method of the EventStream class isprotected
to ensure that intermediate event streams - those created by methods likemap
,flatMap
,filter
, etc. - will not be used to directly publish events to them. The source stream exposes this method for public use.- Definition Classes
Publishes the event to all subscriber, using the given execution context.
Publishes the event to all subscriber, using the given execution context.
- Value Params
- ec
The execution context used for dispatching. The default implementation ensures that if
ec
is the same as the execution context used to register the subscriber, the subscriber will be called immediately. Otherwise, a future working in the subscriber's execution context will be created andec
will be ignored.- event
The event to be published.
- See also
EventStream.publish
Inherited methods
Creates a new event stream of events of type V
by applying a partial function which maps the original event of type E
to an event of type V
. If the partial function doesn't work for the emitted event, nothing will be emitted in the
new event stream. Basically, it's filter + map.
Creates a new event stream of events of type V
by applying a partial function which maps the original event of type E
to an event of type V
. If the partial function doesn't work for the emitted event, nothing will be emitted in the
new event stream. Basically, it's filter + map.
- Type Params
- V
The type of the resulting event.
- Value Params
- pf
A partial function which for an original event of type
E
may produce an event of typeV
.
- Returns
A new event stream of type
V
.- Inherited from
- EventStream
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.- Inherited from
- EventSource
Creates a new EventStream[E]
by filtering events emitted by the original one.
Creates a new EventStream[E]
by filtering events emitted by the original one.
- Value Params
- f
A filtering function which for each event emitted by the original stream returns true or false. Only events for which
f(event)
returns true will be emitted in the resulting stream.
- Returns
A new event stream emitting only filtered events.
- Inherited from
- EventStream
Creates a new EventStream[V]
by mapping each event of the original EventStream[E]
to a new event stream and
switching to it. The usual use case is that the event from the original stream serves to make a decision which
next stream we should be listening to. When another event is emitted by the original stream, we may stay listening
to that second one, or change our previous decision.
Creates a new EventStream[V]
by mapping each event of the original EventStream[E]
to a new event stream and
switching to it. The usual use case is that the event from the original stream serves to make a decision which
next stream we should be listening to. When another event is emitted by the original stream, we may stay listening
to that second one, or change our previous decision.
- Type Params
- V
The type of the resulting event stream.
- Value Params
- f
The function mapping each event of type
E
to an event stream of typeV
.
- Returns
A new or already existing event stream to which we switch as the result of receiving the original event.
- Inherited from
- EventStream
An alias for the on
method with the default ExecutionContext.
An alias for the on
method with the default ExecutionContext.
- Inherited from
- EventSource
A shorthand for next
which additionally unwraps the cancellable future
A shorthand for next
which additionally unwraps the cancellable future
- Inherited from
- EventStream
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
- Inherited from
- EventSource
Assuming that the event emitted by the stream can be interpreted as a boolean, this method creates a new event stream
of type Unit
which emits unit events for each original event which is interpreted as false.
Assuming that the event emitted by the stream can be interpreted as a boolean, this method creates a new event stream
of type Unit
which emits unit events for each original event which is interpreted as false.
- Returns
A new event stream of units.
- Inherited from
- EventStream
Assuming that the event emitted by the stream can be interpreted as a boolean, this method creates a new event stream
of type Unit
which emits unit events for each original event which is interpreted as true.
Assuming that the event emitted by the stream can be interpreted as a boolean, this method creates a new event stream
of type Unit
which emits unit events for each original event which is interpreted as true.
- Returns
A new event stream of units.
- Inherited from
- EventStream
Creates a new EventStream[V]
by mapping events of the type E
emitted by the original one.
Creates a new EventStream[V]
by mapping events of the type E
emitted by the original one.
- Type Params
- V
The type of the resulting event.
- Value Params
- f
The function mapping each event of type
E
into exactly one event of typeV
.
- Returns
A new event stream of type
V
.- Inherited from
- EventStream
Creates a new EventStream[V]
by mapping events of the type E
emitted by the original one.
Creates a new EventStream[V]
by mapping events of the type E
emitted by the original one.
- Type Params
- V
The type of the resulting event.
- Value Params
- f
A function which for a given event of the type
E
will return a future of the typeV
. If the future finishes with success, the resulting event of the typeV
will be emitted by the new stream. Two events, coming one after another, are guaranteed to be mapped in the same order even if the processing for the second event finishes before the processing for the first one.
- Returns
A new event stream of type
V
.- Inherited from
- EventStream
Produces a CancellableFuture which will finish when the next event is emitted in the parent event stream.
Produces a CancellableFuture which will finish when the next event is emitted in the parent event stream.
- Value Params
- context
Internally, the method creates a subscription to the event stream, and an EventContext can be provided to manage it. In practice it's rarely needed. The subscription will be destroyed when the returning future is finished or cancelled.
- Returns
A cancellable future which will finish with the next event emitted by the event stream.
- Inherited from
- EventStream
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
- Inherited from
- EventSource
Registers a subscriber in a specified execution context and returns the subscription. An optional event context can also be provided by the user for managing the subscription instead of doing it manually. When an event is published in the event stream, the subscriber function will be called in the given execution context instead of the one of the publisher.
Registers a subscriber in a specified execution context and returns the subscription. An optional event context can also be provided by the user for managing the subscription instead of doing it manually. When an event is published in the event stream, the subscriber function will be called in the given execution context instead of the one of the publisher.
- Value Params
- body
A function which consumes the event
- ec
An
ExecutionContext
in which the body 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 stream and the body function
- See also
- Definition Classes
- Inherited from
- EventStream
Registers a subscriber which will always be called in the same execution context in which the event was published. An optional event context can be provided by the user for managing the subscription instead of doing it manually.
Registers a subscriber which will always be called in the same execution context in which the event was published. An optional event context can be provided by the user for managing the subscription instead of doing it manually.
- 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 event stream and the body function
- See also
- Definition Classes
- Inherited from
- EventStream
A shorthand for registering a subscriber function in this event stream which only purpose is to publish events emitted by this stream in a given SourceStream. The subscriber function will be called in the execution context of the original publisher.
A shorthand for registering a subscriber function in this event stream which only purpose is to publish events emitted by this stream in a given SourceStream. The subscriber function will be called in the execution context of the original publisher.
- Value Params
- ec
An EventContext which can be used to manage the subscription (optional).
- sourceStream
The source stream in which events emitted by this stream will be published.
- Returns
A new Subscription to this event stream.
- See also
- Inherited from
- EventStream
Creates a new event stream of events of type V
where each event is a result of applying a function which combines
the previous result of type V
with the original event of type E
that triggers the emission of the new one.
Creates a new event stream of events of type V
where each event is a result of applying a function which combines
the previous result of type V
with the original event of type E
that triggers the emission of the new one.
- Type Params
- V
The type of the resulting event.
- Value Params
- f
The function which combines the previous result of type
V
with a new original event of typeE
to produce a new result of typeV
.- zero
The initial value of type
V
used to produce the first new event when the first original event comes in.
- Returns
A new event stream of type
V
.- Inherited from
- EventStream
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
- Inherited from
- EventSource
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
- Inherited from
- EventSource
Empties the set of subscribers and calls unWire
if disableAutowiring
wasn't called before.
Empties the set of subscribers and calls unWire
if disableAutowiring
wasn't called before.
- Inherited from
- EventSource
An alias for filter
used in the for/yield notation.
An alias for filter
used in the for/yield notation.
- Inherited from
- EventStream
Creates a new event stream by merging the original stream with another one of the same type. The resulting stream will emit events coming from both sources.
Creates a new event stream by merging the original stream with another one of the same type. The resulting stream will emit events coming from both sources.
- Value Params
- stream
The other event stream of the same type of events.
- Returns
A new event stream, emitting events from both original streams.
- Inherited from
- EventStream