scala.util

DynamicVariable

class DynamicVariable[T] extends AnyRef

DynamicVariables provide a binding mechanism where the current value is found through dynamic scope, but where access to the variable itself is resolved through static scope.

The current value can be retrieved with the value method. New values should be pushed using the withValue method. Values pushed via withValue only stay valid while the withValue's second argument, a parameterless closure, executes. When the second argument finishes, the variable reverts to the previous value.

Usage of withValue looks like this:

 someDynamicVariable.withValue(newValue) {
   // ... code called in here that calls value ...
   // ... will be given back the newValue ...
 }
 

Each thread gets its own stack of bindings. When a new thread is created, the DynamicVariable gets a copy of the stack of bindings from the parent thread, and from then on the bindings for the new thread are independent of those for the original thread.

source: DynamicVariable.scala
    version
  1. 1.1, 2007-5-21

    authors:
  1. Lex Spoon

Inherited
  1. Hide All
  2. Show all
  1. AnyRef
  2. Any
Visibility
  1. Public
  2. All

Instance constructors

  1. new DynamicVariable(init: T)

Value Members

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

  2. def !=(arg0: Any): Boolean

    o != arg0 is the same as !(o == (arg0)).

  3. def ##(): Int

  4. def $asInstanceOf[T0](): T0

  5. def $isInstanceOf[T0](): Boolean

  6. def ==(arg0: AnyRef): Boolean

    o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).

  7. def ==(arg0: Any): Boolean

    o == arg0 is the same as o.equals(arg0).

  8. def asInstanceOf[T0]: T0

    This method is used to cast the receiver object to be of type T0.

  9. def clone(): AnyRef

    This method creates and returns a copy of the receiver object.

  10. def eq(arg0: AnyRef): Boolean

    This method is used to test whether the argument (arg0) is a reference to the receiver object (this).

  11. def equals(arg0: Any): Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

  12. def finalize(): Unit

    This method is called by the garbage collector on the receiver object when garbage collection determines that there are no more references to the object.

  13. def getClass(): java.lang.Class[_ <: java.lang.Object]

    Returns a representation that corresponds to the dynamic class of the receiver object.

  14. def hashCode(): Int

    Returns a hash code value for the object.

  15. def isInstanceOf[T0]: Boolean

    This method is used to test whether the dynamic type of the receiver object is T0.

  16. def ne(arg0: AnyRef): Boolean

    o.ne(arg0) is the same as !(o.eq(arg0)).

  17. def notify(): Unit

    Wakes up a single thread that is waiting on the receiver object's monitor.

  18. def notifyAll(): Unit

    Wakes up all threads that are waiting on the receiver object's monitor.

  19. def synchronized[T0](arg0: T0): T0

  20. def toString(): String

    Returns a string representation of the object.

  21. def value: T

    Retrieve the current value

  22. def value_=(newval: T): Unit

    Change the currently bound value, discarding the old value.

  23. def wait(): Unit

  24. def wait(arg0: Long, arg1: Int): Unit

  25. def wait(arg0: Long): Unit

  26. def withValue[S](newval: T)(thunk: ⇒ S): S

    Set the value of the variable while executing the specified thunk.