pub trait BackgroundTask: Send {
// Required methods
fn id(&self) -> TaskId;
fn run(&mut self, hub: &Sender<Event>, shutdown: &ShutdownSignal);
// Provided methods
fn stop(&mut self) { ... }
fn finished_event(&self) -> Option<Event> { ... }
}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.
Provided Methods§
Sourcefn stop(&mut self)
fn stop(&mut self)
Called when the task is being stopped.
Override this to perform cleanup. The default implementation does nothing.
Sourcefn finished_event(&self) -> Option<Event>
fn finished_event(&self) -> Option<Event>
Returns a “finished” event to send after the task thread exits.
The TaskManager sends this event after
observing the task’s thread as finished. The default returns None.