pub struct Supervisor<P: Protocol> { /* private fields */ }Expand description
Starts a supervised connection for a Protocol.
The task it spawns holds one connection at a time and keeps these rules (AD-11):
- Pings on the wall clock. A ping goes out every
Timing::ping_intervalwhatever the traffic, and also while the consumer’s queue is full: the task then races the queue’s space against the ping timer and reads nothing more, and the time it waits does not count as silence. None goes out while a membership change is in flight, whichTiming::stale_afterbounds. - Staleness. Silence for
Timing::stale_after, by the protocol’s liveness rule, replaces the connection. - Follow-ups. After each decoded frame that leaves the connection up,
the frame
Protocol::follow_upreturns is sent withinTiming::stale_after; a send that fails or outlives it replaces the connection, as a failed ping does. - No drops. No decoded event is dropped; a bounded queue holds the task back instead.
- Outage markers. At most one
Protocol::disconnectedper outage, and exactly oneProtocol::reconnected, even when the membership stops being wanted during the outage. - Not wanted. A membership that stops being wanted on a healthy connection closes it politely, with no marker, and ends the stream.
- Rotation. A connection older than
Timing::max_connection_ageis closed politely and replaced at once. - Membership during an outage. A change made during an outage goes to
Protocol::record, and a held one is applied after the reconnect. - The consumer gone. Dropping
Supervisedends the task promptly, andSupervised::closedoes not wait on a consumer that never read.
Reconnects wait out Timing::backoff’s schedule, with no cap on
attempts, or the Protocol::retry_after of the failure before them when
that is longer, up to Timing::max_backoff (DRIFT R11); each attempt is
bounded by Timing::connect_timeout. The task logs under the
polyoxide_ws target.
The task runs on the injected runtime and dials through
the injected socket_transport, each the
target’s default when none is given.
The basis is one socket crate’s former supervised tier (ws/supervised.rs,
deleted in Story 4.6), with another socket crate’s former loop (replaced
in Story 4.7 by a router over one supervisor per path) for rotation,
outage markers, changes recorded during an outage, the start in an outage
and the consumer’s departure. Neither kept pinging behind a full queue.
Implementations§
Source§impl<P: Protocol> Supervisor<P>
impl<P: Protocol> Supervisor<P>
Sourcepub fn new(protocol: P, timing: Timing) -> Self
pub fn new(protocol: P, timing: Timing) -> Self
A supervisor for protocol on timing, on the target’s default runtime
and socket transport until runtime and
socket_transport say otherwise.
Sourcepub fn runtime(self, runtime: Arc<dyn Runtime>) -> Self
pub fn runtime(self, runtime: Arc<dyn Runtime>) -> Self
Run the task’s timers, clock reads and spawn on runtime.
Sourcepub fn socket_transport(self, transport: Arc<dyn SocketTransport>) -> Self
pub fn socket_transport(self, transport: Arc<dyn SocketTransport>) -> Self
Dial every attempt through transport.
Sourcepub async fn connect(
self,
membership: P::Membership,
) -> Result<Supervised<P>, P::Error>
pub async fn connect( self, membership: P::Membership, ) -> Result<Supervised<P>, P::Error>
Connect, replay membership, and start supervising. Any failure of
that first attempt is returned, so a setup that is wrong is reported
rather than retried.
Sourcepub async fn start(
self,
membership: P::Membership,
) -> Result<Supervised<P>, P::Error>
pub async fn start( self, membership: P::Membership, ) -> Result<Supervised<P>, P::Error>
As connect, except that a first failure
Protocol::recover would retry starts the stream in an outage: the
protocol’s disconnected for it, then the
backoff and the attempts that follow. Only a failure it would
Stop on is returned.