Expand description
Long-running background task infrastructure.
This module provides a trait-based system for defining and managing background tasks that run alongside the main application loop.
§Architecture
BackgroundTasktrait defines the interface for long-running tasksTaskManagerspawns and manages task lifecyclesShutdownSignalprovides graceful shutdown coordination
§Example
ⓘ
use cadmus_core::task::{BackgroundTask, TaskId, ShutdownSignal};
use std::sync::mpsc::Sender;
use cadmus_core::view::Event;
struct MyTask;
impl BackgroundTask for MyTask {
fn id(&self) -> TaskId {
TaskId::MyTask
}
fn run(&mut self, hub: &Sender<Event>, shutdown: &ShutdownSignal) {
while !shutdown.should_stop() {
// Do work...
if shutdown.wait(Duration::from_secs(60)) {
break;
}
}
}
}Modules§
- dbus_
monitor 🔒 - D-Bus system bus monitor for debugging.
- hello_
world 🔒 - Example background task for testing the task infrastructure.
- wifi_
status_ 🔒monitor - WiFi status monitor using dhcpcd-dbus.
Structs§
- Running
Task 🔒 - Shutdown
Signal - Signal for coordinating graceful shutdown of background tasks.
- Task
Manager - Manages the lifecycle of background tasks.
Enums§
- Task
Error - Errors that can occur during task management operations.
- TaskId
- Unique identifier for a background task.
Traits§
- Background
Task - A long-running background task.
Functions§
- register_
startup_ tasks - Registers background tasks that run at startup.