Skip to main content

PeriodicTask

Trait PeriodicTask 

Source
pub trait PeriodicTask: Send + 'static {
    // Required method
    fn tick(&mut self) -> impl Future<Output = Result<(), TickError>> + Send;

    // Provided method
    fn shutdown(&mut self) -> impl Future<Output = Result<(), TickError>> + Send { ... }
}
Available on crate feature concurrency only.
Expand description

A task that runs on a fixed interval.

Implementations may hold mutable state – tick takes &mut self. Replies / outputs propagate through the state itself (AtomicU64 counters, ArcSwap<T> config handles, etc.) – tick returns Result<(), TickError> purely for error signalling.

Required Methods§

Source

fn tick(&mut self) -> impl Future<Output = Result<(), TickError>> + Send

Called once per interval tick.

Provided Methods§

Source

fn shutdown(&mut self) -> impl Future<Output = Result<(), TickError>> + Send

Called once after the shutdown token fires, before the worker task exits. Default: no-op.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§