Source[+A]
consists of the covariant read-only operations of Ref[A]
.
Source[+A]
consists of the covariant read-only operations of Ref[A]
.
- Companion
- object
Value members
Inherited methods
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 bytxn
.- Throws
- IllegalStateException
if
txn
is not active.
- Inherited from
- SourceLike
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 bytxn
.- Throws
- IllegalStateException
if
txn
is not active.
- Inherited from
- SourceLike
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 thisRef
.- Inherited from
- SourceLike
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 Ref
s.
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 bytxn
.- Inherited from
- SourceLike