pub struct TaskScheduler { /* private fields */ }Expand description
A scheduler for one-shot and periodic background tasks.
All tasks are cancelled when TaskScheduler::shutdown is called or when
the scheduler is dropped.
Implementations§
Source§impl TaskScheduler
impl TaskScheduler
Sourcepub fn schedule_once<F, Fut>(
&self,
delay: Duration,
label: impl Into<String>,
f: F,
) -> TaskId
pub fn schedule_once<F, Fut>( &self, delay: Duration, label: impl Into<String>, f: F, ) -> TaskId
Schedule a one-shot task that executes after delay.
Returns a TaskId that can be used to cancel the task.
Sourcepub fn schedule_periodic<F, Fut>(
&self,
interval: Duration,
label: impl Into<String>,
f: F,
) -> TaskId
pub fn schedule_periodic<F, Fut>( &self, interval: Duration, label: impl Into<String>, f: F, ) -> TaskId
Schedule a periodic task that runs every interval.
The task function receives the current tick count (starting at 1).
The first execution happens after interval elapses.
Returns a TaskId that can be used to cancel the task.
Sourcepub async fn cancel(&self, id: TaskId) -> bool
pub async fn cancel(&self, id: TaskId) -> bool
Cancel a previously scheduled task.
Returns true if the task was found and cancelled.
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
Return the number of active (not yet completed / cancelled) tasks.
Trait Implementations§
Source§impl Clone for TaskScheduler
impl Clone for TaskScheduler
Source§fn clone(&self) -> TaskScheduler
fn clone(&self) -> TaskScheduler
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TaskScheduler
impl Debug for TaskScheduler
Auto Trait Implementations§
impl Freeze for TaskScheduler
impl !RefUnwindSafe for TaskScheduler
impl Send for TaskScheduler
impl Sync for TaskScheduler
impl Unpin for TaskScheduler
impl UnsafeUnpin for TaskScheduler
impl !UnwindSafe for TaskScheduler
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