Represents an event emitted by a Publisher
class.
Represents an event emitted by a Publisher
class.
An Event
can be either a Fire
or a Stop
.
The type of data contained by the event.
An EventJoin is a transformer that takes in events of type A
and B
from two parent EventStreams and produces any number
of new events of type C
in response.
An EventJoin is a transformer that takes in events of type A
and B
from two parent EventStreams and produces any number
of new events of type C
in response.
To create an EventJoin, implement the three required methods:
protected def leftParent: EventStream[A] protected def rightParent: EventStream[B] protected def handle(event: Either[Event[A], Event[B]]): Boolean
Generally, handle
will call fire
and/or stop
.
**Note:** to see the method signatures in this documentation, make
sure to select "Visibility: All".
An EventPipe is a transformer that takes in events of type A
from a single parent EventStream and produces any number of
new events of type B
in response.
An EventPipe is a transformer that takes in events of type A
from a single parent EventStream and produces any number of
new events of type B
in response.
To create an EventPipe, implement the two required methods:
protected def parent: EventStream[A] protected def handle(event: Event[A]): Boolean
Generally, handle
will call fire
and/or stop
.
**Note** to see the method signatures in this documentation, make
sure to select "Visibility: All".
EventSource is an implementation of EventStream that adds fire
and stop
methods.
EventSource is an implementation of EventStream that adds fire
and stop
methods.
Usage in client code will generally look something like
class CoolThings { private val _events = EventSource[Thing] // don't expose `fire` and `stop` publicly: EventStream is read-only def events: EventStream[Thing] = _events def doThings = { events fire new Thing(...) } }
An EventStream represents a (potentially finite) series of events that may occur at any time in the future.
An EventStream represents a (potentially finite) series of events that may occur at
any time in the future. EventStreams are stylistic replacements for Publishers
(from the Publisher/Subscriber, or Observer pattern). Events are produced as Event
instances - either a Fire or Stop. Each Fire
event produced by an EventStream
represents a single "data". The Stop
event represents the end of the stream.
Once an EventStream produces a Stop
event, it is considered finished and will produce no more events.
There are several ways to attach event handlers to an EventStream. The most low-level
way is to use the sink
method, which operates on Event
instances. The foreach
method is used to attach a handler that operates only on data from Fire
events.
onNext
and onEnd
attach handlers to the next Fire
and a Stop
, respectively.
Attaching event handlers requires an implicit Observer, which is used to manage
references between the handler and the stream.
EventStreams can be transformed and combined in a variety of ways like filtering, mapping, and concatenation.
Below is a working example of EventStream usage.
class Example extends App with Observer { // Create an EventStream instance. EventSource is a subtype of // EventStream, with the addition of `fire` and `stop` methods. val stream = EventSource[Int] // Create a mapped version of the EventStream val mappedStream = stream.map(_ * 2) // Attach an event handler, using the `foreach` syntax for(i <- stream) println("Int event: " + i) for(i <- mappedStream) println("Mapped event: " + i) // Attach an "end" event handler stream onEnd { println("Got the end") } // fire some events stream fire 1 // (prints "Int event: 1") // (prints "Mapped event: 2") stream fire 5 // (prints "Int event: 5") // (prints "Mapped event: 10") // stop the stream stream.stop // (prints "Got the end") }
Represents a single item from a stream of events.
Represents a single item from a stream of events.
the type of the item in the event
the item in the event
A memory management assistant.
A memory management assistant. The expected usage is that an Observer
instance will be the only thing that holds strong references to some
collection of objects; once the Observer
instance is no longer
strongly-reachable (can be garbage collected), then neither will the
collection of objects that it references.
An implicit Observer
is required when interacting with Source
s, to
facilitate "automatic" memory management. To create an Observer
, either
explicitly do so:
implicit object myObserver extends Observer
or mix one into the containing class:
class Worker extends Observer { //do things that require an implicit Observer }
Typeclass for types that can get the current time.
Typeclass for types that can get the current time. EventStream methods
that generate a time stamp of type T
will require an implicitly-available
instance of Time[T]
. A default implementation is available as SystemTime,
which simply returns the result of System.currentTimeMillis
.
The type of the time.
Represents the end of a stream of events.
An instance of the Time
typeclass, for Long
times.
An instance of the Time
typeclass, for Long
times.
The currentTime
will always return the result of
System.currentTimeMillis
.