pub struct BackgroundTasks { /* private fields */ }Expand description
Background tasks that run in rounds until shutdown, or once.
Every round runs as its own tokio task. A round that panics is logged and the task continues. On shutdown no new round starts, a running round or one-off task is not interrupted.
Implementations§
Source§impl BackgroundTasks
impl BackgroundTasks
pub fn new() -> Self
Sourcepub fn shutdown_token(&self) -> CancellationToken
pub fn shutdown_token(&self) -> CancellationToken
Cancelled on shutdown. Rounds that may run for a long time, e.g. docs builds, use it to stop early.
pub fn request_shutdown(&self)
Sourcepub fn spawn_periodic<F, Fut>(
&self,
name: &'static str,
interval: Duration,
first_round: FirstRound,
round: F,
)
pub fn spawn_periodic<F, Fut>( &self, name: &'static str, interval: Duration, first_round: FirstRound, round: F, )
Run round every interval. A round that takes longer than the
interval delays the next one.
Sourcepub fn spawn_loop<F, Fut>(&self, name: &'static str, round: F)
pub fn spawn_loop<F, Fut>(&self, name: &'static str, round: F)
Run round repeatedly, starting immediately. Each round returns the
delay until the next one.
Sourcepub fn spawn_tracked<Fut>(&self, task: Fut) -> JoinHandle<Fut::Output> ⓘ
pub fn spawn_tracked<Fut>(&self, task: Fut) -> JoinHandle<Fut::Output> ⓘ
Run task once. Shutdown waits for it like for a running round.
Sourcepub fn spawn_once<Fut>(&self, name: &'static str, task: Fut) -> JoinHandle<()> ⓘ
pub fn spawn_once<Fut>(&self, name: &'static str, task: Fut) -> JoinHandle<()> ⓘ
Run task once and log it if it panics. Shutdown waits for it like
for a running round.
Sourcepub async fn wait_for_shutdown(&self, timeout: Duration)
pub async fn wait_for_shutdown(&self, timeout: Duration)
Wait until shutdown is requested, then up to timeout for the running
rounds to finish.
Trait Implementations§
Source§impl Clone for BackgroundTasks
impl Clone for BackgroundTasks
Source§impl Debug for BackgroundTasks
impl Debug for BackgroundTasks
Auto Trait Implementations§
impl Freeze for BackgroundTasks
impl RefUnwindSafe for BackgroundTasks
impl Send for BackgroundTasks
impl Sync for BackgroundTasks
impl Unpin for BackgroundTasks
impl UnsafeUnpin for BackgroundTasks
impl UnwindSafe for BackgroundTasks
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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