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§
Sourcefn run(&mut self, hub: &Sender<Event>, shutdown: &ShutdownSignal)
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.