pub trait ReconnectPolicy:
Send
+ Sync
+ 'static {
// Required method
fn start(&self) -> Box<dyn ReconnectSchedule>;
}Expand description
Decides how long a session waits between attempts to reconnect after it loses its connection to the ngrok service, and when it stops trying. Set it with SessionBuilder::reconnect_policy.
It is implemented for closures returning a ReconnectSchedule. For example, to give up after five failed attempts, waiting a second longer after each:
builder.reconnect_policy(|| {
let mut failures = 0;
move |_err: &ConnectError| {
failures += 1;
(failures < 5).then(|| Duration::from_secs(failures))
}
});The inner closure needs its parameter’s type written out, &ConnectError:
without it, Rust infers a closure for one particular lifetime, which is not
a ReconnectSchedule.
Required Methods§
Sourcefn start(&self) -> Box<dyn ReconnectSchedule>
fn start(&self) -> Box<dyn ReconnectSchedule>
Called each time the session loses its connection, before its first reconnect attempt, which is immediate. The schedule it returns decides the waits of that outage only.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".