pub struct TaskManager {
tasks: HashMap<TaskId, RunningTask>,
}Expand description
Manages the lifecycle of background tasks.
The task manager spawns tasks in dedicated threads and provides methods to stop individual tasks or all tasks at once.
Fields§
§tasks: HashMap<TaskId, RunningTask>Implementations§
Source§impl TaskManager
impl TaskManager
Sourcepub fn start(
&mut self,
task: Box<dyn BackgroundTask>,
hub: Sender<Event>,
) -> Result<TaskId, TaskError>
pub fn start( &mut self, task: Box<dyn BackgroundTask>, hub: Sender<Event>, ) -> Result<TaskId, TaskError>
Starts a background task in a new thread.
The task receives a clone of hub for sending events and a
ShutdownSignal for graceful termination.
Returns an error if a task with the same ID is already running.
Sourcepub fn stop(&mut self, id: &TaskId) -> Result<(), TaskError>
pub fn stop(&mut self, id: &TaskId) -> Result<(), TaskError>
Stops a running task by ID.
Sends the shutdown signal and waits for the task thread to finish. Returns an error if the task is not running.
Sourcepub fn stop_all(&mut self)
pub fn stop_all(&mut self)
Stops all running tasks.
Sends shutdown signals to all tasks and waits for them to finish.
Sourcefn cleanup_finished(&mut self)
fn cleanup_finished(&mut self)
Removes entries for tasks whose threads have finished.
Sourcepub fn is_running(&mut self, id: &TaskId) -> bool
pub fn is_running(&mut self, id: &TaskId) -> bool
Returns true if a task with the given ID is running.
Sourcepub fn running_tasks(&mut self) -> Vec<TaskId>
pub fn running_tasks(&mut self) -> Vec<TaskId>
Returns the IDs of all running tasks.
Trait Implementations§
Source§impl Default for TaskManager
impl Default for TaskManager
Auto Trait Implementations§
impl Freeze for TaskManager
impl !RefUnwindSafe for TaskManager
impl Send for TaskManager
impl Sync for TaskManager
impl Unpin for TaskManager
impl !UnwindSafe for TaskManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
The none-equivalent value.