bililive_core/retry/
config.rs1use std::fmt::{Debug, Formatter, Result as FmtResult};
2use std::time::Duration;
3
4use stream_reconnect::ReconnectOptions;
5
6use super::policy::BEBIterator;
7
8#[derive(Clone)]
10pub struct RetryConfig(ReconnectOptions);
11
12impl RetryConfig {
13 pub fn new<F, I, IN>(duration_generator: F) -> Self
21 where
22 F: 'static + Send + Sync + Fn() -> IN,
23 I: 'static + Send + Sync + Iterator<Item = Duration>,
24 IN: IntoIterator<IntoIter = I, Item = Duration>,
25 {
26 Self(ReconnectOptions::new().with_retries_generator(duration_generator))
27 }
28}
29
30impl From<RetryConfig> for ReconnectOptions {
31 fn from(o: RetryConfig) -> Self {
32 o.0
33 }
34}
35
36impl Debug for RetryConfig {
37 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
38 f.debug_tuple("RetryConfig")
39 .field(&"<ReconnectOptions>")
40 .finish()
41 }
42}
43
44impl Default for RetryConfig {
45 fn default() -> Self {
46 Self::new(BEBIterator::default)
47 }
48}