Function seed::app::streams::backoff

source ·
pub fn backoff<MsU>(
    max_seconds: Option<u32>,
    handler: impl FnOnce(usize) -> MsU + Clone + 'static
) -> impl Stream<Item = MsU>
Expand description

Stream retries count in increasing intervals.

Algorithm - Truncated exponential backoff

Arguments

  • max_seconds - Typically 32 or 64 seconds. Default is 32.
  • handler - Receives the number of retries (starting from 1); Has to return Msg, Option<Msg> or ().

Example

orders.stream(streams::backoff(None, |_retries| Msg::OnTick));
orders.stream_with_handle(streams::backoff(Some(15), |_| log!("Tick!")));

Panics

Panics when the handler doesn’t return Msg, Option<Msg> or (). (It will be changed to a compile-time error).