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
- Typically32
or64
seconds. Default is32
.handler
- Receives the number of retries (starting from 1); Has to returnMsg
,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).