final class Ref[A] extends AnyVal with Serializable
A mutable atomic reference for the IO monad. This is the IO equivalent of
a volatile var, augmented with atomic operations, which make it useful as a
reasonably efficient (if low-level) concurrency primitive.
for { ref <- Ref(2) v <- ref.update(_ + 3) _ <- putStrLn("Value = " + v) // Value = 5 } yield ()
- Alphabetic
- By Inheritance
- Ref
- Serializable
- Serializable
- AnyVal
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
final
def
get: IO[Nothing, A]
Reads the value from the
Ref. -
def
getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
modify[B](f: (A) ⇒ (B, A)): IO[Nothing, B]
Atomically modifies the
Refwith the specified function, which computes a return value for the modification.Atomically modifies the
Refwith the specified function, which computes a return value for the modification. This is a more powerful version ofupdate. -
final
def
set(a: A): IO[Nothing, Unit]
Writes a new value to the
Ref, with a guarantee of immediate consistency (at some cost to performance). -
final
def
setLater(a: A): IO[Nothing, Unit]
Writes a new value to the
Refwithout providing a guarantee of immediate consistency. -
def
toString(): String
- Definition Classes
- Any
-
final
def
update(f: (A) ⇒ A): IO[Nothing, A]
Atomically modifies the
Refwith the specified function.Atomically modifies the
Refwith the specified function. This is not implemented in terms ofmodifypurely for performance reasons.