pub struct SyncPeriodicTasks { /* private fields */ }Expand description
A main instance which spawns the task executor.
let spt = SyncPeriodicTasks::new(1.try_into().unwrap()).unwrap();
let task1 = TaskStruct1::new(2, send);
let task1_ptt = PeriodicTaskTime::Relative(TimerExpMode::<RelativeTime>::new_interval(RelativeTime::new_time(1, 0)));
let task1_guard = s.add("task1", task1, task1_ptt).unwrap();This instance should be kept somewhere and dropped only if the task executor WITH all spawned tasks are no longer needed.
Implementations§
Source§impl SyncPeriodicTasks
impl SyncPeriodicTasks
Sourcepub fn new(threads_cnt: NonZeroUsize) -> TimerResult<Self>
pub fn new(threads_cnt: NonZeroUsize) -> TimerResult<Self>
Creates new instance. An amount of threads allocated for the task executor should be specified. All threads will be started immidiatly. For small tasks one thread will be enough. For a large amount of tasks, especially it tasks are waken up oftenly then at least two threads should be allocated.
§Arguments
threads_cnt- a NonZeroUsize amount of threads.
§Returns
The Result is returned as alias TimerResult.
Sourcepub fn add<T>(
&self,
task_name: impl Into<String>,
task: T,
task_time: PeriodicTaskTime,
) -> TimerResult<PeriodicTaskGuard>where
T: PeriodicTask,
pub fn add<T>(
&self,
task_name: impl Into<String>,
task: T,
task_time: PeriodicTaskTime,
) -> TimerResult<PeriodicTaskGuard>where
T: PeriodicTask,
Adds and spawns the task,
§Arguments
-
task_name- a task name. used only for identification purposes in debug messages. -
task- a task which should be executed. It should implenet PeriodicTask. -
task_time- PeriodicTaskTime a time when the task must be spawned.
§Returns
The Result is returned as alias TimerResult.
Sourcepub fn check_thread_status(&self) -> Option<String>
pub fn check_thread_status(&self) -> Option<String>
Checks if any thread have crashed and no longer works.
§Returns
A Option is retuerned with the inner data:
-
Option::Some with the thread name String that have quit.
-
Option::None indicating that everthing is fine.
Trait Implementations§
Source§impl Clone for SyncPeriodicTasks
impl Clone for SyncPeriodicTasks
Source§fn clone(&self) -> SyncPeriodicTasks
fn clone(&self) -> SyncPeriodicTasks
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more