1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use ;
/// How long to wait before the next reconnection attempt, and when to stop
/// trying.
///
/// The three built-in shapes —
/// [`Constant`](crate::client::ReconnectionConfig::Constant),
/// [`Linear`](crate::client::ReconnectionConfig::Linear) and
/// [`Exponential`](crate::client::ReconnectionConfig::Exponential) — cover a
/// delay that depends on nothing but the attempt number. This is for a delay
/// that depends on something else: a circuit breaker, a health signal read from
/// elsewhere, a backoff coordinated across a pool, a schedule that refuses to
/// reconnect during a maintenance window.
///
/// The trait is implemented for any `Fn(u32) -> Option<Duration>`, so a closure
/// is enough when the policy only shapes the delay:
///
/// ```
/// use rustis::client::{Config, CustomReconnectionPolicy, ReconnectionConfig};
/// use std::time::Duration;
///
/// let mut config = Config::default();
/// config.reconnection = ReconnectionConfig::Custom(CustomReconnectionPolicy::new(
/// |attempt: u32| (attempt <= 10).then(|| Duration::from_millis(250)),
/// ));
/// ```
///
/// # What the client guarantees
///
/// [`next_delay`](Self::next_delay) is called once per attempt, from the network
/// task, with `attempt` counting from `1` and reset to `1` by every successful
/// reconnection. It must not block: it runs on the task that also drives the
/// connection.
///
/// Answering `None` ends the client for good — the network task stops and every
/// later command fails, which
/// [`Client::is_terminated`](crate::client::Client::is_terminated) reports. A
/// long-lived service should return a capped delay rather than `None`.
///
/// Jitter is the policy's own business here: the built-in shapes add theirs
/// because their delay is otherwise identical across a fleet, and nothing is
/// added to what this returns.
/// A [`ReconnectionPolicy`] as held by
/// [`ReconnectionConfig::Custom`](crate::client::ReconnectionConfig::Custom).
///
/// The wrapper exists so a [`Config`](crate::client::Config) stays `Clone` and
/// `Debug`: a policy is neither, and its `Debug` says only that one is
/// injected.
;