cats.effect.std.Mutex
See theMutex companion object
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 Objecttrait Matchableclass Any