object Var
Note: There is a Java-friendly API for this object: com.twitter.util.Vars.
- Alphabetic
- By Inheritance
- Var
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
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
- def apply[T](init: T, e: Event[T]): Var[T]
Constructs a Var from an initial value plus an event stream of changes.
- def apply[T](init: T): Var[T] with Updatable[T] with Extractable[T]
Create a new, updatable Var with an initial value.
Create a new, updatable Var with an initial value. We call such Vars independent -- derived Vars being dependent on these.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def async[T](empty: T)(update: (Updatable[T]) => Closable): Var[T]
Create a new Var whose values are provided asynchronously by
update
.Create a new Var whose values are provided asynchronously by
update
. The returned Var is dormant until it is observed:update
is called by-need. Such observations are also reference counted so that simultaneous observations do not result in multiple invocations ofupdate
. When the last observer stops observing, the com.twitter.util.Closable returned fromupdate
is closed. Subsequent observations result in a new call toupdate
.empty
is used to fill the returned Var untilupdate
has provided a value. The first observation of the returned Var is synchronous with the call toupdate
--it is guaranteed the the opportunity to fill the Var before the observer sees any value at all.Updates from
update
are ignored after the returned com.twitter.util.Closable is closed. - def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[T <: AnyRef](vars: List[Var[T]]): Var[List[T]]
Collect a List of Vars into a new Var of List.
Collect a List of Vars into a new Var of List.
- vars
a java.util.List of Vars
- returns
a Var[java.util.List[A]] containing the collected values from vars.
- def collect[T](vars: Seq[Var[T]]): Var[Seq[T]]
Collect a collection of Vars into a Var of collection.
Collect a collection of Vars into a Var of collection. Var.collect can result in a stack overflow if called with a large sequence. Var.collectIndependent breaks composition with respect to update propagation. That is, collectIndependent can fail to correctly update interdependent vars, but is safe for independent vars.
// Example of difference between collect and collectIndependent: val v1 = Var(1) val v2 = v1.map(_*2) val vCollect = Var.collect(Seq(v1, v2)).map { case Seq(a, b) => (a, b) } val vCollectIndependent = Var.collectIndependent(Seq(v1, v2)).map { case Seq(a, b) => (a, b) } val refCollect = new AtomicReference[Seq[(Int, Int)]] vCollect.changes.build.register(Witness(refCollect)) val refCollectIndependent = new AtomicReference[Seq[(Int, Int)]] vCollectIndependent.changes.build.register(Witness(refCollectIndependent)) v1() = 2 // refCollect == Vector((1,2), (2,4)) // refCollectIndependent == Vector((1,2), (2,2), (2,4))
- def collectIndependent[T](vars: Seq[Var[T]]): Var[Seq[T]]
Collect a collection of Vars into a Var of collection.
Collect a collection of Vars into a Var of collection. Var.collectIndependent breaks composition with respect to update propagation. That is, collectIndependent can fail to correctly update interdependent vars, but is safe for independent vars.
// Example of difference between collect and collectIndependent: val v1 = Var(1) val v2 = v1.map(_*2) val vCollect = Var.collect(Seq(v1, v2)).map { case Seq(a, b) => (a, b) } val vCollectIndependent = Var.collectIndependent(Seq(v1, v2)).map { case Seq(a, b) => (a, b) } val refCollect = new AtomicReference[Seq[(Int, Int)]] vCollect.changes.build.register(Witness(refCollect)) val refCollectIndependent = new AtomicReference[Seq[(Int, Int)]] vCollectIndependent.changes.build.register(Witness(refCollectIndependent)) v1() = 2 // refCollect == Vector((1,2), (2,4)) // refCollectIndependent == Vector((1,2), (2,2), (2,4))
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- 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 patch[CC[_], T](diffs: Event[Diff[CC, T]])(implicit arg0: Diffable[CC]): Var[CC[T]]
Patch reconstructs a Var based on observing the incremental changes presented in the underlying Diffs.
- def sample[T](v: Var[T]): T
Sample the current value of this Var.
Sample the current value of this Var. Note that this may lead to surprising results for lazily defined Vars: the act of observing a Var may be kick off a process to populate it; the value returned from sample may then reflect an intermediate value.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def value[T](v: T): Var[T] with Extractable[T]
Create a new, constant, v-valued Var.
- 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()
- object Observer
- object Sampled