pub struct FallbackCoordinator { /* private fields */ }Expand description
Coordinates fallback across the components of a runtime generation.
Fallback is signalled through a CancellationToken and acknowledged by lifetime: a future
wrapped with FallbackCoordinator::track counts as pending until it is dropped, whether it
returned, was cancelled or panicked, so there is nothing a component has to remember to call
on its way out. FallbackCoordinator::trigger_fallback_and_wait cancels the token and
resolves once no tracked future is left, which it checks rather than infers from a wakeup: a
future tracked after the trigger, or after every other one already finished, is still waited
for.
This is meant to be used together with crate::task_manager::TaskManager:
task_manager.spawn(fallback_coordinator.track(async move {
tokio::select! {
_ = fallback_token.cancelled() => { /* clean up */ }
// ...
}
}));A coordinator serves one fallback cycle: once the wait returned, the runtime instantiates a fresh one for the next generation.
Implementations§
Source§impl FallbackCoordinator
impl FallbackCoordinator
pub fn new() -> Self
Sourcepub fn token(&self) -> CancellationToken
pub fn token(&self) -> CancellationToken
Get the cancellation token that signals fallback.
Sourcepub fn track<F: Future>(
&self,
fut: F,
) -> impl Future<Output = F::Output> + use<F>
pub fn track<F: Future>( &self, fut: F, ) -> impl Future<Output = F::Output> + use<F>
Wrap a fallback-relevant future so that fallback waits for it until it is dropped.
Tracking starts here, not when the future is first polled, so a tracked future handed to a spawner is pending from the moment it exists. Track before fallback is triggered or from inside a future that is itself tracked: a future tracked after the wait has observed the tracker empty belongs to no generation and is not waited for.
Sourcepub async fn trigger_fallback_and_wait(&self)
pub async fn trigger_fallback_and_wait(&self)
Trigger fallback and wait until every tracked future has been dropped.