abstract class Ref[F[_], A] extends AnyRef
An asynchronous, 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
.
- Source
- Ref.scala
- Alphabetic
- By Inheritance
- Ref
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new Ref()
Abstract Value Members
-
abstract
def
access: F[(A, (A) ⇒ F[Boolean])]
Obtains a snapshot of the current value, and a setter for updating it.
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 toaccess
uses its setter first.Once it has noop'd or been used once, a setter never succeeds again.
Satisfies:
r.access.map(_._1) == r.get
r.access.flatMap { case (v, setter) => setter(f(v)) } == r.tryUpdate(f).map(_.isDefined)
-
abstract
def
get: F[A]
Obtains the current value.
Obtains the current value.
Since
Ref
is always guaranteed to have a value, the returned action completes immediately after being bound. -
abstract
def
modify[B](f: (A) ⇒ (A, B)): F[B]
Like
tryModify
but does not complete until the update has been successfully made. -
abstract
def
modifyState[B](state: State[A, B]): F[B]
Like tryModifyState but retries the modification until successful.
-
abstract
def
set(a: A): F[Unit]
Sets the current value to
a
.Sets the current value to
a
.The returned action completes after the reference has been successfully set.
Satisfies:
r.set(fa) *> r.get == fa
-
abstract
def
tryModify[B](f: (A) ⇒ (A, B)): F[Option[B]]
Like
tryUpdate
but allows the update function to return an output value of typeB
.Like
tryUpdate
but allows the update function to return an output value of typeB
. The returned action completes withNone
if the value is not updated successfully andSome(b)
otherwise. -
abstract
def
tryModifyState[B](state: State[A, B]): F[Option[B]]
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. -
abstract
def
tryUpdate(f: (A) ⇒ A): F[Boolean]
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. -
abstract
def
update(f: (A) ⇒ A): F[Unit]
Modifies the current value using the supplied update function.
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)
Concrete 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
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
getAndSet(a: A): F[A]
Replaces the current value with
a
, returning the previous value. -
def
getAndUpdate(f: (A) ⇒ A): F[A]
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.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
mapK[G[_]](f: ~>[F, G])(implicit F: Functor[F]): Ref[G, A]
Modify the context
F
using transformationf
. -
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()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
updateAndGet(f: (A) ⇒ A): F[A]
Updates the current value using
f
, and returns the updated value. -
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
This is the API documentation for the cats-effect library.
See the cats.effect package for a quick overview.
Links
Canonical documentation links:
Related Cats links (the core):