pub struct ScheduledTaskManager { /* private fields */ }Implementations§
Source§impl ScheduledTaskManager
impl ScheduledTaskManager
pub fn new() -> Self
Sourcepub fn add_fixed_rate_task<F, Fut>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64
pub fn add_fixed_rate_task<F, Fut>( &self, initial_delay: Duration, period: Duration, task_fn: F, ) -> u64
Adds a fixed-rate scheduled task to the task manager.
§Arguments
initial_delay- The delay before the first execution of the task.period- The interval between task executions.task_fn- A function that defines the task to be executed. It takes aCancellationTokenas an argument and returns aFuturethat resolves to aResult<()>.
§Returns
A TaskId representing the unique identifier of the scheduled task.
§Notes
- Tasks are executed at fixed intervals, even if previous executions overlap.
Sourcepub fn add_fixed_delay_task<F, Fut>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64
pub fn add_fixed_delay_task<F, Fut>( &self, initial_delay: Duration, period: Duration, task_fn: F, ) -> u64
Adds a fixed-delay scheduled task to the task manager.
§Arguments
initial_delay- The delay before the first execution of the task.period- The interval between task executions.task_fn- A function that defines the task to be executed. It takes aCancellationTokenas an argument and returns aFuturethat resolves to aResult<()>.
§Returns
A TaskId representing the unique identifier of the scheduled task.
§Notes
- Tasks are executed serially, with a delay after each task completes.
Sourcepub fn add_fixed_rate_no_overlap_task<F, Fut>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64
pub fn add_fixed_rate_no_overlap_task<F, Fut>( &self, initial_delay: Duration, period: Duration, task_fn: F, ) -> u64
Adds a fixed-rate-no-overlap scheduled task to the task manager.
§Arguments
initial_delay- The delay before the first execution of the task.period- The interval between task executions.task_fn- A function that defines the task to be executed. It takes aCancellationTokenas an argument and returns aFuturethat resolves to aResult<()>.
§Returns
A TaskId representing the unique identifier of the scheduled task.
§Notes
- Tasks are executed at fixed intervals, but overlapping executions are skipped.
Sourcepub fn add_scheduled_task<F, Fut>(
&self,
mode: ScheduleMode,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64
pub fn add_scheduled_task<F, Fut>( &self, mode: ScheduleMode, initial_delay: Duration, period: Duration, task_fn: F, ) -> u64
Adds a scheduled task to the task manager.
§Arguments
mode- The scheduling mode for the task. Determines how the task is executed:FixedRate: Aligns the beats, allowing tasks to pile up if they take too long.FixedDelay: Executes tasks serially, with a delay after each task completes.FixedRateNoOverlap: Aligns the beats but skips execution if the previous task is still running.
initial_delay- The delay before the first execution of the task.period- The interval between task executions.task_fn- A function that defines the task to be executed. It takes aCancellationTokenas an argument and returns aFuturethat resolves to aResult<()>.
§Returns
A TaskId representing the unique identifier of the scheduled task.
§Notes
- The task function is executed asynchronously.
- The
CancellationTokencan be used to gracefully cancel the task. - The task is added to the internal task manager and can be managed (e.g., canceled or aborted) later.
Sourcepub fn cancel_task(&self, id: u64)
pub fn cancel_task(&self, id: u64)
Graceful cancellation
Sourcepub fn abort_task(&self, id: u64)
pub fn abort_task(&self, id: u64)
Roughly abort
Sourcepub fn cancel_all(&self)
pub fn cancel_all(&self)
Batch cancel
pub fn task_count(&self) -> usize
Source§impl ScheduledTaskManager
impl ScheduledTaskManager
Sourcepub fn add_fixed_rate_task_async<F>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64where
F: AsyncFnMut(CancellationToken) -> Result<()> + Send + Sync + 'static,
for<'a> <F as AsyncFnMut<(CancellationToken,)>>::CallRefFuture<'a>: Send,
pub fn add_fixed_rate_task_async<F>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64where
F: AsyncFnMut(CancellationToken) -> Result<()> + Send + Sync + 'static,
for<'a> <F as AsyncFnMut<(CancellationToken,)>>::CallRefFuture<'a>: Send,
Adds a fixed-rate scheduled task to the task manager asynchronously.
§Arguments
initial_delay- The delay before the first execution of the task.period- The interval between task executions.task_fn- A function that defines the task to be executed. It takes aCancellationTokenas an argument and returns aResult<()>.
§Returns
A TaskId representing the unique identifier of the scheduled task.
§Notes
- Tasks are executed at fixed intervals, even if previous executions overlap.
- The task function is executed asynchronously.
Sourcepub fn add_fixed_delay_task_async<F>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64where
F: AsyncFnMut(CancellationToken) -> Result<()> + Send + Sync + 'static,
for<'a> <F as AsyncFnMut<(CancellationToken,)>>::CallRefFuture<'a>: Send,
pub fn add_fixed_delay_task_async<F>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64where
F: AsyncFnMut(CancellationToken) -> Result<()> + Send + Sync + 'static,
for<'a> <F as AsyncFnMut<(CancellationToken,)>>::CallRefFuture<'a>: Send,
Adds a fixed-delay scheduled task to the task manager asynchronously.
§Arguments
initial_delay- The delay before the first execution of the task.period- The interval between task executions.task_fn- A function that defines the task to be executed. It takes aCancellationTokenas an argument and returns aResult<()>.
§Returns
A TaskId representing the unique identifier of the scheduled task.
§Notes
- Tasks are executed serially, with a delay after each task completes.
- The task function is executed asynchronously.
Sourcepub fn add_fixed_rate_no_overlap_task_async<F>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64where
F: AsyncFnMut(CancellationToken) -> Result<()> + Send + Sync + 'static,
for<'a> <F as AsyncFnMut<(CancellationToken,)>>::CallRefFuture<'a>: Send,
pub fn add_fixed_rate_no_overlap_task_async<F>(
&self,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64where
F: AsyncFnMut(CancellationToken) -> Result<()> + Send + Sync + 'static,
for<'a> <F as AsyncFnMut<(CancellationToken,)>>::CallRefFuture<'a>: Send,
Adds a fixed-rate-no-overlap scheduled task to the task manager asynchronously.
§Arguments
initial_delay- The delay before the first execution of the task.period- The interval between task executions.task_fn- A function that defines the task to be executed. It takes aCancellationTokenas an argument and returns aResult<()>.
§Returns
A TaskId representing the unique identifier of the scheduled task.
§Notes
- Tasks are executed at fixed intervals, but overlapping executions are skipped.
- The task function is executed asynchronously.
Sourcepub fn add_scheduled_task_async<F>(
&self,
mode: ScheduleMode,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64where
F: AsyncFnMut(CancellationToken) -> Result<()> + Send + Sync + 'static,
for<'a> <F as AsyncFnMut<(CancellationToken,)>>::CallRefFuture<'a>: Send,
pub fn add_scheduled_task_async<F>(
&self,
mode: ScheduleMode,
initial_delay: Duration,
period: Duration,
task_fn: F,
) -> u64where
F: AsyncFnMut(CancellationToken) -> Result<()> + Send + Sync + 'static,
for<'a> <F as AsyncFnMut<(CancellationToken,)>>::CallRefFuture<'a>: Send,
Adds a scheduled task to the task manager asynchronously.
§Arguments
mode- The scheduling mode for the task. Determines how the task is executed:FixedRate: Aligns the beats, allowing tasks to pile up if they take too long.FixedDelay: Executes tasks serially, with a delay after each task completes.FixedRateNoOverlap: Aligns the beats but skips execution if the previous task is still running.
initial_delay- The delay before the first execution of the task.period- The interval between task executions.task_fn- A function that defines the task to be executed. It takes aCancellationTokenas an argument and returns aFuturethat resolves to aResult<()>.
§Returns
A TaskId representing the unique identifier of the scheduled task.
§Notes
- The task function is executed asynchronously.
- The
CancellationTokencan be used to gracefully cancel the task. - The task is added to the internal task manager and can be managed (e.g., canceled or aborted) later.
Trait Implementations§
Source§impl Clone for ScheduledTaskManager
impl Clone for ScheduledTaskManager
Source§fn clone(&self) -> ScheduledTaskManager
fn clone(&self) -> ScheduledTaskManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more