// Check if the bearer token isn't expired yet, if so get a new one
Check if the bearer token isn't expired yet, if so get a new one
Check if the bearer token isn ' t expired yet if so get a new one
async fn ensure_authenticated(&self) -> Result<()> {
        // Verify that the credentials are not expired yet
        // read lock: This will block until the write lock (if present) is released
        if self.credentials.read().await.expires_at < Instant::now() {
            trace!("Credentials appear to be expired, preparing to double check in a upgradable read lock and refresh if required");
            // Acquire a write lock, only one write lock can access the data at once
            let write_lock = self.credentials.write().await;
            // We make sure no other write lock has updated the credentials in the time we were waiting to acquire the write lock
            if write_lock.expires_at < Instant::now() {
                debug!("Credentials are expired, refreshing the authentication");
                self.refresh_authentication(write_lock).await?;
            }
        }
        Ok(())
    }
async fn ensure_authenticated ( & self ) -> Result < ( ) > { // Verify that the credentials are not expired yet // read lock: This will block until the write lock (if present) is released if self . credentials . read ( ) . await . expires_at < Instant :: now ( ) { trace ! ( " " ) ; // Acquire a write lock, only one write lock can access the data at once let write_lock = self . credentials . write ( ) . await ; // We make sure no other write lock has updated the credentials in the time we were waiting to acquire the write lock if write_lock . expires_at < Instant :: now ( ) { debug ! ( " " ) ; self . refresh_authentication ( write_lock ) . await ? ; } } Ok ( ( ) ) }
Check if the bearer token isn't expired yet, if so get a new one
Check if the bearer token isn ' t expired yet if so get a new one
&self