The Std.Sync.Broadcast module implements a broadcasting primitive for sending values
to multiple consumers. It maintains a queue of values and supports both synchronous
and asynchronous waiting.
This module is heavily inspired by Std.Sync.Channel as well as
tokio’s broadcast implementation.
Errors that may be thrown while interacting with the broadcast channel API.
- closed : Error
Tried to send to a closed broadcast channel.
- alreadyClosed : Error
Tried to close an already closed broadcast channel.
- notSubscribed : Error
Tried to unsubscribe a channel that already is not part of it.
Instances For
Equations
- Std.Broadcast.instReprError = { reprPrec := Std.Broadcast.instReprError.repr }
Equations
- One or more equations did not get rendered due to their size.
- Std.Broadcast.instReprError.repr Std.Broadcast.Error.closed prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "Std.Broadcast.Error.closed")).group prec✝
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Equations
- Std.instMonadLiftBroadcastIO = { monadLift := fun {α : Type} (x : EIO Std.Broadcast.Error α) => EIO.toIO (fun (x : Std.Broadcast.Error) => IO.Error.userError (toString x)) x }
A multi-subscriber broadcast that delivers each message to all current subscribers.
Supports only bounded buffering and an asynchronous API; to switch into
synchronous mode use Broadcast.sync.
Unlike Std.Channel, each message is received by every subscriber instead of just one.
Subscribers only receive messages sent after they have subscribed (unless otherwise specified).
- inner : Std.Bounded✝ α
Instances For
A receiver for a Broadcast channel that can asynchronously receive messages.
Each receiver gets a copy of every message sent to the broadcast channel after
the receiver was created. Multiple receivers can exist for the same broadcast,
and each will receive all messages independently.
- inner : Std.Bounded.Receiver✝ α
Instances For
Creates a new broadcast channel.
Equations
- Std.Broadcast.new capacity h = do let __do_lift ← Std.Bounded.new✝ capacity h pure { inner := __do_lift }
Instances For
Try to send a value to the broadcast channel, if this can be completed right away without blocking return
true, otherwise don't send the value and return false.
Equations
- ch.trySend v = Std.Bounded.trySend✝ (Std.Broadcast.inner✝ ch) v
Instances For
Closes a Broadcast channel.
Equations
- ch.close = liftM (Std.Bounded.close✝ (Std.Broadcast.inner✝ ch))
Instances For
Send a value through the broadcast channel, returning a task that will resolve once the transmission could be completed.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Try to receive a value from the broadcast receiver, if a message is available right away
return some value, otherwise return none without blocking.
Equations
Instances For
Receive a value from the broadcast receiver, returning a task that will resolve with the next available message. This will block until a message is available.
Equations
Instances For
Creates a Selector that resolves once the broadcast channel ch has data available and provides that that data.
Equations
Instances For
ch.forAsync f calls f for every message received on ch.
Note that if this function is called twice, each message will only arrive at exactly one invocation.
Equations
- Std.Broadcast.Receiver.forAsync f ch prio = Std.Bounded.Receiver.forAsync✝ f (Std.Broadcast.Receiver.inner✝ ch) prio
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Std.Broadcast.Receiver.instAsyncReadOptionOfInhabited = { read := fun (receiver : Std.Broadcast.Receiver α) => Std.Internal.IO.Async.Async.ofIOTask (liftM receiver.recv) }
Equations
- One or more equations did not get rendered due to their size.
A multi-subscriber broadcast that delivers each message to all current subscribers. Supports only bounded buffering and an asynchronous API.
It's the sync version of Broadcast.
Equations
Instances For
A receiver for a Broadcast channel that can asynchronously receive messages.
Each receiver gets a copy of every message sent to the broadcast channel after
the receiver was created. Multiple receivers can exist for the same broadcast,
and each will receive all messages independently.
It's the sync version of Broadcast.Receiver.
Equations
Instances For
Creates a new broadcast channel.
Equations
- Std.Broadcast.Sync.new capacity h = Std.Broadcast.new capacity h
Instances For
Try to send a value to the broadcast channel, if this can be completed right away without blocking return
true, otherwise don't send the value and return false.
Equations
- ch.trySend v = Std.Broadcast.trySend ch v
Instances For
Send a value through the channel, blocking until the transmission could be completed.
Equations
- ch.send v = do let __do_lift ← liftM (Std.Broadcast.send ch v) IO.ofExcept =<< liftM (IO.wait __do_lift)
Instances For
Try to receive a value from the broadcast receiver, if a message is available right away
return some value, otherwise return none without blocking.
Equations
Instances For
for msg in ch.sync do ... receives all messages in the channel until it is closed.
Equations
- One or more equations did not get rendered due to their size.