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
takeandputasreceiveandsend, and - As a binary semaphore
MVar[Unit], withtakeandputaswaitandsignal.
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
- Protected
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(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def isEmpty: UIO[Boolean]
Check whether the
MVaris empty.Check whether the
MVaris 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, theMVarmay have been filled (or emptied) - so be extremely careful when using this operation. UsetryTakeinstead if possible. - final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def modify[B](f: (A) => (B, A)): UIO[B]
A slight variation on
updatethat 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 theMVaris currently full,putwill wait until it becomes empty. - def read: UIO[A]
Atomically read the contents of an
MVar.Atomically read the contents of an
MVar. If theMVaris currently empty,readwill wait until it is full.readis guaranteed to receive the nextput. - def swap(x: A): UIO[A]
Take a value from an
MVar, put a new value into theMVarand 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 theMVaris currently empty,takewill wait until it is full. After atake, theMVaris 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. ThetryPutfunction attempts to put the valuexinto theMVar, returningtrueif it was successful, orfalseotherwise. - def tryRead: UIO[Option[A]]
A non-blocking version of
read.A non-blocking version of
read. ThetryReadfunction returns immediately, withNoneif theMVarwas empty, orSome(x)if theMVarwas full with contentsx. - def tryTake: UIO[Option[A]]
A non-blocking version of
take.A non-blocking version of
take. ThetryTakeaction returns immediately, withNoneif theMVarwas empty, orSome(x)if theMVarwas full with contentsx. AftertryTake, theMVaris left empty. - def update(f: (A) => A): UIO[Unit]
Replaces the contents of an
MVarwith the result off(a). - final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()