BackgroundTask

Trait BackgroundTask 

Source
pub trait BackgroundTask: Send {
    // Required methods
    fn id(&self) -> TaskId;
    fn run(&mut self, hub: &Sender<Event>, shutdown: &ShutdownSignal);

    // Provided method
    fn stop(&mut self) { ... }
}
Expand description

A long-running background task.

Implement this trait to define tasks that run in dedicated threads alongside the main application loop. Tasks receive the event hub to dispatch events and a shutdown signal for graceful termination.

Required Methods§

Source

fn id(&self) -> TaskId

Returns the unique identifier for this task.

Source

fn run(&mut self, hub: &Sender<Event>, shutdown: &ShutdownSignal)

Runs the task until shutdown is requested.

This method is called in a dedicated thread. Use hub to send events to the main loop and shutdown to check for termination.

Provided Methods§

Source

fn stop(&mut self)

Called when the task is being stopped.

Override this to perform cleanup. The default implementation does nothing.

Implementors§