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
impl SelfUpdatingPollingTask
sourcepub fn new<F>(interval: Duration, task: F) -> Self
pub fn new<F>(interval: Duration, task: F) -> Self
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.
sourcepub fn new_with_checker<F>(interval: Duration, task: F) -> Self
pub fn new_with_checker<F>(interval: Duration, task: F) -> Self
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.