case class Activity[+T](run: Var[State[T]]) extends Product with Serializable
Activity, like Var, is a value that varies over time; but, richer than Var, these values have error and pending states. They are useful for modeling a process that produces values, but also intermittent failures (e.g. address resolution, reloadable configuration).
As such, an Activity can be in one of three states:
- Pending: output is pending;
- Ok: an output is available; and
- Failed: the process failed with an exception.
An Activity may transition between any state at any time. They are typically constructed from Events, but they can also be constructed without arguments.
val (activity, witness) = Activity[Int]() println(activity.sample()) // throws java.lang.IllegalStateException: Still pending
As you can see, Activities start in a Pending state. Attempts to sample an Activity that is pending will fail. Curiously, the constructor for an Activity also returns a Witness.
Recall that a Witness is the interface to something that you can send values to; and in this case, that something is the Activity.
witness.notify(Return(1)) println(activity.sample()) // prints 1
(For implementers, it may be useful to think of Activity as a monad transformer for an Op monad over Var where Op is like a Try with an additional pending state.)
- Alphabetic
- By Inheritance
- Activity
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[U](f: PartialFunction[T, U]): Activity[U]
Build a new activity by applying
f
to each value.Build a new activity by applying
f
to each value. Whenf
is not defined for this activity's current value, the derived activity becomes pending. - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def flatMap[U](f: (T) => Activity[U]): Activity[U]
The activity which behaves as
f
applied to Ok values. - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def handle[U >: T](h: PartialFunction[Throwable, U]): Activity[U]
Recover a failed activity.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def join[U](that: Activity[U]): Activity[(T, U)]
Join two activities.
- def map[U](f: (T) => U): Activity[U]
Map a T-typed activity to a U-typed one.
- def mapState[U](f: (State[T]) => State[U]): Activity[U]
Map the states of a T-typed activity to a U-typed one.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- val run: Var[State[T]]
- def sample(): T
Sample the current value of this activity.
Sample the current value of this activity. Sample throws an exception if the activity is in pending state or has failed.
- def stabilize: Activity[T]
Stabilize the value of this activity such that once an Ok value has been returned it stops error propagation and instead returns the last Ok value.
- def states: Event[State[T]]
An Event of states.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def transform[U](f: (State[T]) => Activity[U]): Activity[U]
The activity which behaves as
f
to the state of this activity. - def values: Event[Try[T]]
An Event containing only nonpending values.
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()