Skip to main content

spawn_bearer_refresh

Function spawn_bearer_refresh 

Source
pub fn spawn_bearer_refresh(
    broker: Arc<dyn TokenBroker>,
    bearer: String,
    initial: BearerIdentity,
    cadence: Duration,
) -> (JoinHandle<()>, Receiver<RefreshEvent>)
Expand description

Spawn a background task that periodically re-validates bearer via broker and emits RefreshEvents on the returned channel. The task exits after emitting one RefreshEvent::AuthLost; dropping the JoinHandle aborts it sooner.

Per spec §4.7, the initial resolve_bearer call already happened at stream open (so the route handler has the live BearerIdentity); this task picks up after that. The caller supplies initial so the helper can compute the first sleep duration from the recorded expires_at.