This module contains the implementation of Std.Notify. Std.Notify provides a lightweight
notification primitive for signaling between tasks or threads. It supports both synchronous
and asynchronous waiting, and is useful for cases where you want to notify one or more waiters
that an event has occurred.
Unlike a channel, Std.Notify does not buffer messages or carry data. It's simply a trigger.
If no one is waiting, notifications are lost. If one or more waiters are present, exactly one
will be woken up per notification.
- normal {α : Type} (promise : IO.Promise α) : Consumer α
- select {α : Type} (finished : Internal.IO.Async.Waiter α) : Consumer α
Instances For
Equations
- (Std.Notify.Consumer.normal promise).resolve x = do IO.Promise.resolve x promise pure true
- (Std.Notify.Consumer.select waiter).resolve x = waiter.race (pure false) fun (promise : IO.Promise (Except IO.Error α)) => do IO.Promise.resolve (Except.ok x) promise pure true
Instances For
A notify is a synchronization primitive that allows multiple consumers to wait until notify is called.
Instances For
Create a new notify.
Equations
- Std.Notify.new = do let __do_lift ← Std.Mutex.new { consumers := ∅ } pure { state := __do_lift }
Instances For
Notify all currently waiting consumers.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Notify exactly one waiting consumer (if any). Returns true if a consumer was notified, false if no consumers were waiting.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Wait to be notified. Returns a task that completes when notify is called. Note: if notify was called before wait, this will wait for the next notify call.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a selector that waits for notifications
Equations
- One or more equations did not get rendered due to their size.