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 look is not reentrant, thus this mutex.lock.surround(mutex.lock.use_)
will
deadlock.
- See also:
- Companion:
- object
- Source:
- Mutex.scala
class Object
trait Matchable
class Any
Value members
Abstract methods
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.
- Source:
- Mutex.scala
Modify the context F
using natural transformation f
.
Modify the context F
using natural transformation f
.
- Source:
- Mutex.scala