Skip to main content

supervise

Function supervise 

pub async fn supervise<M, F, Fut, Frame>(
    name: &'static str,
    open: F,
    connected: impl Fn() -> Frame,
    wrap: impl Fn(M) -> Frame,
    failed: impl Fn(String) -> Frame,
    tx: Sender<Frame>,
    stale_after: Duration,
    last_error: Arc<LastError>,
    cancel: CancellationToken,
)
where F: Fn() -> Fut, Fut: Future<Output = Result<Streaming<M>, Status>>,
Expand description

Keeps one server-side stream open. connected goes out after every successful open (then the consumer knows a break happened if it is not the first), wrap turns each message into a frame. A stream silent for stale_after is closed and reopened (pings arrive on a healthy stream).

The pause before a reopen grows with each failure (backoff) and goes back to the start only after the stream has delivered a message, not after the open alone: a stream that opens and breaks at once is not tried again at full speed. When the open is refused for good (fatal_open), failed(reason) is sent once and the supervisor ends.