pub struct SelfUpdatingPollingTask { /* private fields */ }
Expand description

Executes a closure with a given frequency where the closure also apply changes to the polling rate.

When SelfUpdatingPollingTask is dropped, the background thread is signaled to perform a clean exit at the first available opportunity. If the thread is currently sleeping, this will occur almost immediately. If the closure is still running, it will happen immediately after the closure finishes. The task joins on the background thread as a best-effort clean exit.

Note nothing special is done to try and keep the thread alive longer. If you terminate the program the default behavior of reaping the thread mid-execution will still occur.

Implementations§

source§

impl SelfUpdatingPollingTask

source

pub fn new<F>(interval: Duration, task: F) -> Self
where F: Fn(&mut Duration) + Send + 'static,

Creates a new background thread that immediately executes the given task.

  • interval The interval to poll at. Note it must be expressible as an u64 in milliseconds.
  • task The closure to execute at every poll.
source

pub fn new_with_checker<F>(interval: Duration, task: F) -> Self
where F: Fn(&mut Duration, &dyn Fn() -> bool) + Send + 'static,

Creates a new background thread that immediately executes the given task.

  • interval The interval to poll at. Note it must be expressible as an u64 in milliseconds.
  • task The closure to execute at every poll. This closure gets access to another function that can assert if the managed task is still active.

If your task is long-running or has iterations (say updating 10 cache entries sequentially), you can assert if the managed task is active to early exit during a clean exit.

Trait Implementations§

source§

impl Drop for SelfUpdatingPollingTask

source§

fn drop(&mut self)

Signals the background thread that it should exit at first available opportunity.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.