Mutex

cats.effect.std.Mutex
See theMutex companion object
abstract class Mutex[F[_]]

A purely functional mutex.

A mutex is a concurrency primitive that can be used to give access to a resource to only one fiber at a time; e.g. a cats.effect.kernel.Ref.

// Assuming some resource r that should not be used concurrently.

Mutex[IO].flatMap { mutex =>
 mutex.lock.surround {
   // Here you can use r safely.
   IO(r.mutate(...))
 }
}

'''Note''': This lock is not reentrant, thus this mutex.lock.surround(mutex.lock.use_) will deadlock.

Attributes

See also:
Companion:
object
Source:
Mutex.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Abstract methods

def lock: Resource[F, Unit]

Returns a cats.effect.kernel.Resource that acquires the lock, holds it for the lifetime of the resource, then releases it.

Returns a cats.effect.kernel.Resource that acquires the lock, holds it for the lifetime of the resource, then releases it.

Attributes

Source:
Mutex.scala
def mapK[G[_]](f: FunctionK[F, G])(implicit G: MonadCancel[G, _]): Mutex[G]

Modify the context F using natural transformation f.

Modify the context F using natural transformation f.

Attributes

Source:
Mutex.scala