Std.Sync
Std.Sync — shared mutable state for Task programs: a `Ref`, a `Mutex`,
Types
type Ref a
type Mutex
type Queue a
Values
close : Queue a -> Task Error ()
Close the queue: later pushes fail, waiting pushes fail, and pops
compareAndSwap : a -> a -> Ref a -> Task Error Bool
`compareAndSwap expected new ref` — store `new` only when the value
get : Ref a -> Task Error a
The value the cell holds now.
newMutex : () -> Task Error Mutex
A new, unlocked mutex. Create one at the top level to share it:
newQueue : Int -> Task Error (Queue a)
`newQueue capacity` — an empty queue that holds at most `capacity`
newRef : a -> Task Error (Ref a)
`newRef initial` — a new cell holding `initial`.
pop : Queue a -> Task Error (Maybe a)
Take the item at the front, waiting until there is one: `Just item`, or
popWithin : Int -> Queue a -> Task Error (Maybe a)
`popWithin ms queue` — `pop`, waiting at most `ms` milliseconds:
push : a -> Queue a -> Task Error ()
`push item queue` — add `item` at the back, waiting while the queue is
set : a -> Ref a -> Task Error ()
`set value ref` — replace the value.
size : Queue a -> Task Error Int
How many items are waiting now.
update : (a -> a) -> Ref a -> Task Error a
`update f ref` — replace the value with `f` applied to it, atomically:
withLock : Mutex -> Task e a -> Task e a
`withLock mutex task` — run `task` while holding `mutex`, so no other