A fiber-safe, concurrent, mutable reference.
Provides safe concurrent access and modification of its contents, by ensuring only one fiber can operate on them at the time. Thus, '''all''' operations may semantically block the calling fiber.
final class ParkingLot(data: AtomicCell[IO, ArraySeq[Boolean]], rnd: Random[IO]) {
def getSpot: IO[Option[Int]] =
data.evalModify { spots =>
val availableSpots =
spots.view.zipWithIndex.collec {
case (idx, true) => idx
}.toList
rnd.shuffleList(availableSpots).map(_.headOption)
}
}
- See also:
cats.effect.kernel.Ref for a non-blocking alternative.
- Companion:
- object
- Source:
- AtomicCell.scala
Value members
Abstract methods
Updates the current value using the provided effectual function, and returns the previous value.
Updates the current value using the provided effectual function, and returns the previous value.
- Source:
- AtomicCell.scala
Like evalUpdate
but allows the update function to return an output value.
Like evalUpdate
but allows the update function to return an output value.
- Source:
- AtomicCell.scala
Like update
but using an effectual function; which is guaranteed to run only once.
Like update
but using an effectual function; which is guaranteed to run only once.
- Source:
- AtomicCell.scala
Updates the current value using the provided effectual function, and returns the updated value.
Updates the current value using the provided effectual function, and returns the updated value.
- Source:
- AtomicCell.scala
Like update
but allows the update function to return an output value.
Like update
but allows the update function to return an output value.
- Source:
- AtomicCell.scala
Concrete methods
Replaces the current value with a
, returning the previous value.
Replaces the current value with a
, returning the previous value.
- Source:
- AtomicCell.scala
Updates the current value using the provided function, and returns the previous value.
Updates the current value using the provided function, and returns the previous value.
- Source:
- AtomicCell.scala
Modifies the current value using the supplied update function.
Modifies the current value using the supplied update function.
- Source:
- AtomicCell.scala
Updates the current value using the provided function, and returns the updated value.
Updates the current value using the provided function, and returns the updated value.
- Source:
- AtomicCell.scala