Skip to main content

refresh_after

Function refresh_after 

Source
pub fn refresh_after(ttl: Duration) -> Duration
Expand description

How long after issuing to renew a token that lives ttl.

Renews ttl/5 (clamped to 5s..120s) before expiry, but never later than half of the lifetime.

§Examples

use std::time::Duration;
use brokapi_finam_protocol::auth::refresh_after;

// A 15 minute token is renewed 2 minutes before it ends.
assert_eq!(refresh_after(Duration::from_secs(900)), Duration::from_secs(780));
// A very short token is renewed at half of its life.
assert_eq!(refresh_after(Duration::from_secs(8)), Duration::from_secs(4));