Packages

abstract class Ref[F[_], A] extends RefSource[F, A] with RefSink[F, A]

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 dependent upon object reference equality.

See also cats.effect.std.AtomicCell class from cats-effect-std for an alternative that ensures exclusive access and effectual updates.

If your contents are an immutable Map[K, V], and all your operations are per-key, consider using cats.effect.std.MapRef.

Source
Ref.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Ref
  2. RefSink
  3. RefSource
  4. Serializable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Ref()

Abstract Value Members

  1. 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 attempts to modify the contents from the snapshot to the new value (and return true). If it cannot do this (because the contents changed since taking the snapshot), the setter is a noop and returns false.

    Satisfies: r.access.map(_._1) == r.get and r.access.flatMap { case (v, setter) => setter(f(v)) } == r.tryUpdate(f).map(_.isDefined).

  2. 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.

    Definition Classes
    RefSource
  3. abstract def modify[B](f: (A) => (A, B)): F[B]

    Like tryModify but retries until the update has been successfully made.

  4. abstract def modifyState[B](state: State[A, B]): F[B]

    Like tryModifyState but retries the modification until successful.

  5. 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.

    Definition Classes
    RefSink
  6. abstract def tryModify[B](f: (A) => (A, B)): F[Option[B]]

    Like tryUpdate but allows the update function to return an output value of type B.

    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.

  7. 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.

  8. 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.

  9. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  9. def flatModify[B](f: (A) => (A, F[B]))(implicit F: MonadCancel[F, _]): F[B]

    Like modify but schedules resulting effect right after modification.

    Like modify but schedules resulting effect right after modification.

    Useful for implementing effectful transition of a state machine, in which an effect is performed based on current state and the state must be updated to reflect that this effect will be performed.

    Both modification and finalizer are within a single uncancelable region, to prevent canceled finalizers from leaving the Ref's value permanently out of sync with effects actually performed. if you need cancellation mechanic in finalizer please see flatModifyFull.

    See also

    modify

    flatModifyFull

  10. def flatModifyFull[B](f: (Poll[F], A) => (A, F[B]))(implicit F: MonadCancel[F, _]): F[B]

    Like modify but schedules resulting effect right after modification.

    Like modify but schedules resulting effect right after modification.

    Unlike flatModify finalizer cancellation could be unmasked via supplied Poll. Modification itself is still uncancelable.

    When used as part of a state machine, cancelable regions should usually have an onCancel finalizer to update the state to reflect that the effect will not be performed.

    See also

    modify

    flatModify

  11. def flatModifyState[B](state: State[A, F[B]])(implicit F: MonadCancel[F, _]): F[B]

    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.

    See also

    modifyState

    flatModifyStateFull

  12. def flatModifyStateFull[B](state: (Poll[F]) => State[A, F[B]])(implicit F: MonadCancel[F, _]): F[B]

    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.

    See also

    modifyState

    flatModifyState

  13. def getAndSet(a: A): F[A]

    Replaces the current value with a, returning the previous value.

  14. 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.

  15. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  18. def mapK[G[_]](f: ~>[F, G])(implicit F: Functor[F]): Ref[G, A]

    Modify the context F using transformation f.

  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  23. def toString(): String
    Definition Classes
    AnyRef → Any
  24. def updateAndGet(f: (A) => A): F[A]

    Updates the current value using f, and returns the updated value.

  25. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  26. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  27. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from RefSink[F, A]

Inherited from RefSource[F, A]

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped