final class MVar[A] extends AnyRef
An MVar[A]
is a mutable location that is either empty or contains a value
of type A
. It has two fundamental operations: put
which fills an MVar
if it is empty and blocks otherwise, and take
which empties an MVar
if it
is full and blocks otherwise. They can be used in multiple different ways:
- As synchronized mutable variables,
- As channels, with
take
andput
asreceive
andsend
, and - As a binary semaphore
MVar[Unit]
, withtake
andput
aswait
andsignal
.
They were introduced in the paper "Concurrent Haskell" by Simon Peyton Jones, Andrew Gordon and Sigbjorn Finne.
- Alphabetic
- By Inheritance
- MVar
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
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] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
isEmpty: UIO[Boolean]
Check whether the
MVar
is empty.Check whether the
MVar
is empty.Notice that the boolean value returned is just a snapshot of the state of the
MVar
. By the time you get to react on its result, theMVar
may have been filled (or emptied) - so be extremely careful when using this operation. UsetryTake
instead if possible. -
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
modify[B](f: (A) ⇒ (B, A)): UIO[B]
A slight variation on
update
that allows a value to be returned (b
) in addition to the modified value of theMVar
. -
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()
-
def
put(x: A): UIO[Unit]
Put a value into an
MVar
.Put a value into an
MVar
. If theMVar
is currently full,put
will wait until it becomes empty. -
def
read: UIO[A]
Atomically read the contents of an
MVar
.Atomically read the contents of an
MVar
. If theMVar
is currently empty,read
will wait until it is full.read
is guaranteed to receive the nextput
. -
def
swap(x: A): UIO[A]
Take a value from an
MVar
, put a new value into theMVar
and return the value taken. -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
take: UIO[A]
Return the contents of the
MVar
.Return the contents of the
MVar
. If theMVar
is currently empty,take
will wait until it is full. After atake
, theMVar
is left empty. -
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
tryPut(x: A): UIO[Boolean]
A non-blocking version of
put
.A non-blocking version of
put
. ThetryPut
function attempts to put the valuex
into theMVar
, returningtrue
if it was successful, orfalse
otherwise. -
def
tryRead: UIO[Option[A]]
A non-blocking version of
read
.A non-blocking version of
read
. ThetryRead
function returns immediately, withNone
if theMVar
was empty, orSome(x)
if theMVar
was full with contentsx
. -
def
tryTake: UIO[Option[A]]
A non-blocking version of
take
.A non-blocking version of
take
. ThetryTake
action returns immediately, withNone
if theMVar
was empty, orSome(x)
if theMVar
was full with contentsx
. AftertryTake
, theMVar
is left empty. -
def
update(f: (A) ⇒ A): UIO[Unit]
Replaces the contents of an
MVar
with the result off(a)
. -
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()