An atomic counter for generating unique IDs
Instances For
Create a new counter starting at 0
Instances For
Create a new counter starting at a given value
Equations
Instances For
Atomically increment and return the previous value
Equations
- c.incrementAndGet = ST.Ref.modifyGet c.value fun (n : Nat) => (n, n + 1)
Instances For
Unbounded Channel #
An unbounded MPSC (multi-producer, single-consumer) channel. Multiple actors can send messages, one actor receives them in order. Uses atomic IO.Ref operations - no mutex needed.
Queue of pending messages
- signal : IO.Ref (IO.Promise Unit)
Promise for signaling new messages (recreated after each wait)
Instances For
Create a new unbounded channel
Equations
- One or more equations did not get rendered due to their size.
Instances For
Send a message to the channel (non-blocking). Uses atomic modify - safe for concurrent sends.
Equations
- ch.send msg = do ST.Ref.modify ch.queue fun (x : Array α) => x.push msg let sig ← ST.Ref.get ch.signal liftM (IO.Promise.resolve () sig)
Instances For
Receive a message from the channel (blocking)
Bounded Channel #
A bounded MPSC channel with backpressure. Senders block when the channel is full. Uses atomic IO.Ref operations - no mutex needed.
Queue of pending messages
- capacity : Nat
Maximum capacity
- notEmptySignal : IO.Ref (IO.Promise Unit)
Signal for receivers (queue not empty)
- notFullSignal : IO.Ref (IO.Promise Unit)
Signal for senders (queue not full)
Instances For
Receive a message from the channel (blocking)
Oneshot Channel #
A oneshot channel for single request-response patterns. Can only be used once: one send, one receive.
- promise : IO.Promise α
Instances For
Create a new oneshot channel
Equations
- Lapis.Concurrent.Channel.Oneshot.new = do let promise ← liftM IO.Promise.new pure { promise := promise }
Instances For
Select (Multi-channel waiting) #
Result of a select operation
- first {α β : Type} : α → SelectResult α β
- second {α β : Type} : β → SelectResult α β