SourceLike

trait SourceLike[+A, Context]

Provides all of the operations of a Source[A], without the ability to get a Source.View.

Provides all of the operations of a Source[A], without the ability to get a Source.View.

Authors

Nathan Bronson

class Object
trait Matchable
class Any
trait RefLike[A, Context]
trait Ref[A]
trait TxnLocal[A]
trait Source[A]

Value members

Abstract methods

def get(txn: Context): A

Performs a transactional read and checks that it is consistent with all reads already made by txn. Equivalent to apply(), which is more concise in many situations.

Performs a transactional read and checks that it is consistent with all reads already made by txn. Equivalent to apply(), which is more concise in many situations.

Value Params
txn

an active transaction.

Returns

the value of the Ref as observed by txn.

Throws
IllegalStateException

if txn is not active.

def getWith[Z](f: A => Z)(txn: Context): Z

Returns f(get), possibly reevaluating f to avoid rollback if a conflicting change is made but the old and new values are equal after application of f. Requires that f(x) == f(y) if x == y.

Returns f(get), possibly reevaluating f to avoid rollback if a conflicting change is made but the old and new values are equal after application of f. Requires that f(x) == f(y) if x == y.

getWith(f) is equivalent to f(relaxedGet({ f(_) == f(_) })), although perhaps more efficient.

Value Params
f

an idempotent function.

Returns

the result of applying f to the value contained in this Ref.

def relaxedGet(equiv: (A, A) => Boolean)(txn: Context): A

Returns the same value as get, but allows the caller to determine whether txn should be rolled back if another thread changes the value of this Ref before txn is committed. If ref.relaxedGet(equiv) returns v0 in txn, another context changes ref to v1, and equiv(v0, v1) == true, then txn won't be required to roll back (at least not due to this read). If additional changes are made to ref additional calls to the equivalence function will be made, always with v0 as the first parameter.

Returns the same value as get, but allows the caller to determine whether txn should be rolled back if another thread changes the value of this Ref before txn is committed. If ref.relaxedGet(equiv) returns v0 in txn, another context changes ref to v1, and equiv(v0, v1) == true, then txn won't be required to roll back (at least not due to this read). If additional changes are made to ref additional calls to the equivalence function will be made, always with v0 as the first parameter.

equiv will always be invoked on the current thread. Extreme care should be taken if the equivalence function accesses any Refs.

As an example, to perform a read that will not be validated during commit you can use the maximally permissive equivalence function:

  val unvalidatedValue = ref.relaxedGet({ (_, _) => true })

To check view serializability rather than conflict serializability for a read:

  val viewSerializableValue = ref.relaxedGet({ _ == _ })

The getWith method provides related functionality.

Value Params
equiv

an equivalence function that returns true if a transaction that observed the first argument will still complete correctly, where the second argument is the actual value that should have been observed.

Returns

a value of the Ref, not necessary consistent with the rest of the reads performed by txn.

Concrete methods

def apply(txn: Context): A

Performs a transactional read and checks that it is consistent with all reads already made by txn. Equivalent to get.

Performs a transactional read and checks that it is consistent with all reads already made by txn. Equivalent to get.

Example:

  val x = Ref(0)
  atomic { implicit t =>
    ...
    val v = x() // perform a read inside a transaction
    ...
  }
Value Params
txn

an active transaction.

Returns

the value of the Ref as observed by txn.

Throws
IllegalStateException

if txn is not active.