A thread-safe, concurrent mutable reference.
Provides safe concurrent access and modification of its content, but no functionality for
synchronisation, which is instead handled by Deferred. For this reason, a Ref
is always
initialised to a value.
The default implementation is nonblocking and lightweight, consisting essentially of a purely
functional wrapper over an AtomicReference
. Consequently it ''must not'' be used to store
mutable data as AtomicReference#compareAndSet
and friends are not threadsafe and are
dependent upon object reference equality.
See also cats.effect.std.AtomicCell
class from cats-effect-std
for an alternative.
Attributes
Members list
Value members
Abstract methods
Obtains a snapshot of the current value, and a setter for updating it. The setter may noop
(in which case false
is returned) if another concurrent call to access
uses its setter
first.
Obtains a snapshot of the current value, and a setter for updating it. The setter may noop
(in which case false
is returned) if another concurrent call to access
uses its setter
first.
Once it has noop'd a setter will never succeed.
Satisfies: r.access.map(_._1) == r.get
r.access.flatMap { case (v, setter) => setter(f(v)) } == r.tryUpdate(f).map(_.isDefined)
Attributes
- Source:
- Ref.scala
Like tryModify
but does not complete until the update has been successfully made.
Like tryModify
but does not complete until the update has been successfully made.
Attributes
- Source:
- Ref.scala
Like tryModifyState but retries the modification until successful.
Like tryUpdate
but allows the update function to return an output value of type B
. The
returned action completes with None
if the value is not updated successfully and
Some(b)
otherwise.
Like tryUpdate
but allows the update function to return an output value of type B
. The
returned action completes with None
if the value is not updated successfully and
Some(b)
otherwise.
Attributes
- Source:
- Ref.scala
Update the value of this ref with a state computation.
Update the value of this ref with a state computation.
The current value of this ref is used as the initial state and the computed output state is
stored in this ref after computation completes. If a concurrent modification occurs, None
is returned.
Attributes
- Source:
- Ref.scala
Attempts to modify the current value once, returning false
if another concurrent
modification completes between the time the variable is read and the time it is set.
Attempts to modify the current value once, returning false
if another concurrent
modification completes between the time the variable is read and the time it is set.
Attributes
- Source:
- Ref.scala
Modifies the current value using the supplied update function. If another modification
occurs between the time the current value is read and subsequently updated, the
modification is retried using the new value. Hence, f
may be invoked multiple times.
Modifies the current value using the supplied update function. If another modification
occurs between the time the current value is read and subsequently updated, the
modification is retried using the new value. Hence, f
may be invoked multiple times.
Satisfies: r.update(_ => a) == r.set(a)
Attributes
- Source:
- Ref.scala
Concrete methods
Like modify but schedules resulting effect right after modification.
Like modify but schedules resulting effect right after modification.
Both modification and finalizer are uncancelable, if you need cancellation mechanic in finalizer please see flatModifyFull.
Attributes
- See also:
- Source:
- Ref.scala
Like modify but schedules resulting effect right after modification.
Like modify but schedules resulting effect right after modification.
Unlike flatModify finalizer cancellation could be masked via supplied Poll
.
Modification itself is still uncancelable.
Attributes
- See also:
- Source:
- Ref.scala
Like modifyState but schedules resulting effect right after state computation & update.
Like modifyState but schedules resulting effect right after state computation & update.
Both modification and finalizer are uncancelable, if you need cancellation mechanic in finalizer please see flatModifyStateFull.
Attributes
- See also:
- Source:
- Ref.scala
Like modifyState but schedules resulting effect right after modification.
Like modifyState but schedules resulting effect right after modification.
Unlike flatModifyState finalizer cancellation could be masked via supplied Poll[F]
.
Modification itself is still uncancelable.
Attributes
- See also:
- Source:
- Ref.scala
Replaces the current value with a
, returning the previous value.
Updates the current value using f
and returns the previous value.
Updates the current value using f
and returns the previous value.
In case of retries caused by concurrent modifications, the returned value will be the last one before a successful update.
Attributes
- Source:
- Ref.scala
Modify the context F
using transformation f
.
Updates the current value using f
, and returns the updated value.