Skip to main content

spawn_background_refresh

Function spawn_background_refresh 

Source
pub fn spawn_background_refresh(
    provider: Arc<dyn OAuthBearerTokenProvider>,
) -> Option<JoinHandle<()>>
Expand description

Starts a background task that keeps provider’s token fresh.

The task calls OAuthBearerTokenProvider::refresh at the time OAuthBearerTokenProvider::refresh_at reports, rather than waiting for the next SASL exchange to notice the cached token needs a refresh. This is krabka’s equivalent of Kafka’s ExpiringCredentialRefreshingLogin background thread.

Returns None when background_refresh_enabled says not to. Otherwise the task runs until its JoinHandle is dropped or aborted, so the caller should abort it (dropping the last reference to provider) once the client using it shuts down.