pub struct TaskManager {
tasks: HashMap<TaskId, RunningTask>,
pending_import_rerun: Option<Option<usize>>,
}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>§pending_import_rerun: Option<Option<usize>>A pending import rerun queued while an import was already running.
Some(library_index) means re-run for that index after current finishes.
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 handle_event(
&mut self,
evt: &Event,
hub: &Sender<Event>,
database: &Database,
settings: &Settings,
) -> bool
pub fn handle_event( &mut self, evt: &Event, hub: &Sender<Event>, database: &Database, settings: &Settings, ) -> bool
Observes an event without consuming it.
Must be called for every event before passing it to the view tree.
Always returns false — it never consumes events.
Sourcefn schedule_import(
&mut self,
library_index: Option<usize>,
hub: &Sender<Event>,
database: &Database,
settings: &Settings,
)
fn schedule_import( &mut self, library_index: Option<usize>, hub: &Sender<Event>, database: &Database, settings: &Settings, )
Schedules an import task, coalescing if one is already running.
Sourcefn schedule_dictionary_index(
&mut self,
hub: &Sender<Event>,
database: &Database,
)
fn schedule_dictionary_index( &mut self, hub: &Sender<Event>, database: &Database, )
Schedules a dictionary index scan, stopping any running instance first.
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 UnsafeUnpin 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
§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>
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>
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)
&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)
&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>
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>
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