reactive

EventStream

trait EventStream[+T] extends Foreachable[T]

An EventStream is a source of events (arbitrary values sent to listener functions). You can fire events from it, you can react to events with any behavior, and you can create derived EventStreams, whose events are based on the original EventStream. The API is modeled after the Scala standard library collections framework.

An EventStream is like a collection in the sense that it consists of multiple values. However, unlike actual collections, the values are not available upon request; they occur whenever they occur. Nevertheless, many operations that apply to collections apply to event streams. To react to events, use foreach or foldLeft. To create derived, transformed EventStreams, use map, flatMap, filter, foldLeft, and the | (union) operator. Note that you can of course use for comprehensions as syntactic sugar for many of the above.

Methods that return a new EventStream generally do not require an (implicit) Observing. Instead, the new EventStream itself holds references to the parent EventStream and the event function (which refers to, or is, the function passed in to the method). (As a result, if you derive EventStreams with a function that performs side effects, in order to ensure that the function is not garbage collected you must retain a reference to the resulting EventStream.)

On the other hand, methods which do require an Observing take functions which are expected perform side effects, and therefore do not hold a reference to the function themselves but rather use the Observing for that purpose. As a result, they will remain in memory as long as the Observing object does.

You can also create a Signal from an EventStream using hold.

T

the type of values fired as events

Source
EventStream.scala
See also

EventSource

Linear Supertypes
Foreachable[T], AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. EventStream
  2. Foreachable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def collect[U](pf: PartialFunction[T, U]): EventStream[U]

    Filter and map in one step.

    Filter and map in one step. Takes a PartialFunction. Whenever an event is received, if the PartialFunction is defined at that event, the value returned by applying it will be fired.

  2. abstract def debugName: String

  3. abstract def debugString: String

  4. abstract def distinct: EventStream[T]

    Returns a derived EventStream that only fires events that are not equal to the previous event.

    Returns a derived EventStream that only fires events that are not equal to the previous event. This can be used to prevent infinite recursion between multiple event streams that are mutually dependent in a consistent manner.

  5. abstract def filter(f: (T) ⇒ Boolean): EventStream[T]

    Returns a new EventStream that propagates a subset of the events that this EventStream fires.

    Returns a new EventStream that propagates a subset of the events that this EventStream fires.

    f

    the predicate function that determines which events will be fired by the new EventStream.

  6. abstract def flatMap[U](f: (T) ⇒ EventStream[U]): EventStream[U]

    Create a new EventStream that consists of the events of the EventStreams returned by f.

    Create a new EventStream that consists of the events of the EventStreams returned by f. f is applied on every event of the original EventStream, and its returned EventStream is used until the next event fired by the original EventStream, at which time the previously returned EventStream is no longer used and a new one is used instead.

    f

    the function that is applied for every event to produce the next segment of the resulting EventStream.

  7. abstract def foldLeft[U](initial: U)(f: (U, T) ⇒ U): EventStream[U]

    Allows one, in a functional manner, to respond to an event while taking into account past events.

    Allows one, in a functional manner, to respond to an event while taking into account past events. For every event t, f is called with arguments (u, t), where u is initially the value of the 'initial' parameter, and subsequently the result of the previous application of f. Returns a new EventStream that, for every event t fired by the original EventStream, fires the result of the application of f (which will also be the next value of u passed to it). Often 'u' will be an object representing some accumulated state. For instance, given an EventStream[Int] named 'es', es.foldLeft(0)(_ + _) would return an EventStream that, for every (integer) event fired by es, would fire the sum of all events that have been fired by es.

  8. abstract def foreach(f: (T) ⇒ Unit)(implicit observing: Observing): Unit

    Registers a listener function to run whenever an event is fired.

    Registers a listener function to run whenever an event is fired. The function is held with a WeakReference and a strong reference is placed in the Observing, so the latter determines the function's gc lifetime.

    f

    a function to be applied on every event

    observing

    the object whose gc lifetime should determine that of the function

    Definition Classes
    EventStreamForeachable
  9. abstract def hold[U >: T](init: U): Signal[U]

    Returns a Signal whose value is initially the 'init' parameter, and after every event fired by this EventStream, the value of that event.

    Returns a Signal whose value is initially the 'init' parameter, and after every event fired by this EventStream, the value of that event.

    init

    the initial value of the signal

  10. abstract def map[U](f: (T) ⇒ U): EventStream[U]

    Returns a new EventStream, that for every event that this EventStream fires, that one will fire an event that is the result of applying 'f' to this EventStream's event.

    Returns a new EventStream, that for every event that this EventStream fires, that one will fire an event that is the result of applying 'f' to this EventStream's event.

    f

    the function that transforms events fired by this EventStream into events to be fired by the resulting EventStream.

  11. abstract def nonblocking: EventStream[T]

    Returns a derived event stream in which event propagation does not happen on the thread firing it and block it.

    Returns a derived event stream in which event propagation does not happen on the thread firing it and block it. This is helpful when handling events can be time consuming. The implementation delegates propagation to an actor (scala standard library), so events are handled sequentially.

  12. abstract def nonrecursive: EventStream[T]

    Returns a derived EventStream that does not fire events during a prior call to fire on the same thread, thus preventing infinite recursion between multiple event streams that are mutually dependent.

  13. abstract def takeWhile(p: (T) ⇒ Boolean): EventStream[T]

    Returns a new EventStream that propagates this EventStream's events until the predicate returns false.

    Returns a new EventStream that propagates this EventStream's events until the predicate returns false.

    p

    the precate function, taking an event as its argument and returning true if event propagation should continue

  14. abstract def throttle(period: Long): EventStream[T]

    Returns an EventStream that only fires events that are not followed by another event within period milliseconds.

    Returns an EventStream that only fires events that are not followed by another event within period milliseconds. For instance, if you want to display some results in response to the user typing, and you do not want to perform more work than necessary, you may want to wait until the user has not typed anything for a full second.

  15. abstract def zipWithStaleness: EventStream[(T, () ⇒ Boolean)]

    Returns an EventStream whose tuple-valued events include a function for testing staleness.

    Returns an EventStream whose tuple-valued events include a function for testing staleness. The events will be of type (T, ()=>Boolean), where T is the type of the parent event stream; and the tuple will contain the event fired in the parent as well as a function that can be used to test whether that event is outdated because a new event has been fired since then. This is especially useful in conjunction with 'nonblocking', because its actor implementation means that a new event cannot be received until the previous event is finished being handled. The test function is useful because it may be desirable to abort the time-consuming work if a new event has been fired since then. Example usage: for((v, isSuperseded) <- eventStream.zipWithStaleness) { doSomework(); if(!isSuperseded()) doSomeMoreWork() }

  16. abstract def |[U >: T](that: EventStream[U]): EventStream[U]

    Union of two EventStreams.

    Union of two EventStreams. Returns a new EventStream that consists of all events fired by both this EventStream and 'that.'

    that

    the other EventStream to combine in the resulting EventStream.

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  18. def toString(): String

    Definition Classes
    AnyRef → Any
  19. def uneither[A, B](implicit ev: <:<[T, Either[A, B]]): (EventStream[A], EventStream[B])

    Converts this EventStream of Eithers into two EventStreams of the Left and Right halves, respectively.

    Converts this EventStream of Eithers into two EventStreams of the Left and Right halves, respectively. For each Left event that this EventStream fires, the first of the returned streams will fire the data inside of that Left. Similarly, for each Right event that this EventStream fires, the second of the returned streams will fire the data inside of that Right.

  20. def unzip[A, B](implicit ev: <:<[T, (A, B)]): (EventStream[A], EventStream[B])

    Converts this EventStream of pairs into two EventStreams of the first and second half of each pair.

    Converts this EventStream of pairs into two EventStreams of the first and second half of each pair. For each event that this EventStream fires, the returned event streams will fire the first half and second half of that event, respectively.

  21. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  22. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  23. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from Foreachable[T]

Inherited from AnyRef

Inherited from Any

Ungrouped