cats.effect.std.AtomicCell
See theAtomicCell companion object A synchronized, 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.zipWithIndex.collect { case (true, idx) => idx }
rnd.shuffleList(availableSpots).map { shuffled =>
val acquired = shuffled.headOption
val next = acquired.fold(spots)(a => spots.updated(a, false)) // mark the chosen spot as taken
(next, shuffled.headOption)
}
}
}
Attributes See also: Companion: object Source: AtomicCell.scala Graph Reset zoom Hide graph Show graph
Supertypes class Object
trait Matchable
class Any
Members list Concise view
Value members
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.
Attributes 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.
Attributes 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.
Attributes 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.
Attributes Source: AtomicCell.scala
Obtains the current value.
Like update
but allows the update function to return an output value.
Like update
but allows the update function to return an output value.
Attributes Source: AtomicCell.scala
Sets the current value to a
.
Replaces the current value with a
, returning the previous value.
Replaces the current value with a
, returning the previous value.
Attributes 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.
Attributes Source: AtomicCell.scala
Modifies the current value using the supplied update function.
Modifies the current value using the supplied update function.
Attributes 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.
Attributes Source: AtomicCell.scala