pub struct TokenRefresher { /* private fields */ }Expand description
Single-flight token refresher keyed by an arbitrary string (typically location ID or company ID). Ensures that concurrent callers for the same key share one refresh request, preventing refresh-token rotation conflicts.
Implementations§
Source§impl TokenRefresher
impl TokenRefresher
pub fn new() -> Self
Sourcepub async fn ensure_valid<F, Fut>(
&self,
key: &str,
token: &mut TokenData,
refresh: F,
) -> Result<()>
pub async fn ensure_valid<F, Fut>( &self, key: &str, token: &mut TokenData, refresh: F, ) -> Result<()>
Acquire a per-key lock and refresh the token if expired.
key is the location/company identifier. token is the current
TokenData (will be updated in place if refreshed). refresh is an
async callable that performs the refresh and returns a new TokenData.
Trait Implementations§
Source§impl Clone for TokenRefresher
impl Clone for TokenRefresher
Source§fn clone(&self) -> TokenRefresher
fn clone(&self) -> TokenRefresher
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for TokenRefresher
impl !UnwindSafe for TokenRefresher
impl Freeze for TokenRefresher
impl Send for TokenRefresher
impl Sync for TokenRefresher
impl Unpin for TokenRefresher
impl UnsafeUnpin for TokenRefresher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more