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

A pool of threads which can run tasks at specific time intervals.

By default, when the pool drops, all pending scheduled executions will be run, but periodic actions will not be rescheduled after that.

If you want different behavior on drop then you can specify it using OnPoolDropBehavior.

Implementations§

source§

impl ScheduledThreadPool

source

pub fn new(num_threads: usize) -> ScheduledThreadPool

Creates a new thread pool with the specified number of threads.

Panics

Panics if num_threads is 0.

source

pub fn builder() -> NumThreadsStage

Returns a builder type to configure a new pool.

source

pub fn with_name(thread_name: &str, num_threads: usize) -> ScheduledThreadPool

👎Deprecated since 0.2.7: use ScheduledThreadPool::builder

Creates a new thread pool with the specified number of threads which will be named.

The substring {} in the name will be replaced with an integer identifier of the thread.

Panics

Panics if num_threads is 0.

source

pub fn execute<F>(&self, job: F) -> JobHandlewhere F: FnOnce() + Send + 'static,

Executes a closure as soon as possible in the pool.

source

pub fn execute_after<F>(&self, delay: Duration, job: F) -> JobHandlewhere F: FnOnce() + Send + 'static,

Executes a closure after a time delay in the pool.

source

pub fn execute_at_fixed_rate<F>( &self, initial_delay: Duration, rate: Duration, f: F ) -> JobHandlewhere F: FnMut() + Send + 'static,

Executes a closure after an initial delay at a fixed rate in the pool.

The rate includes the time spent running the closure. For example, if the rate is 5 seconds and the closure takes 2 seconds to run, the closure will be run again 3 seconds after it completes.

Panics

If the closure panics, it will not be run again.

source

pub fn execute_at_dynamic_rate<F>( &self, initial_delay: Duration, f: F ) -> JobHandlewhere F: FnMut() -> Option<Duration> + Send + 'static,

Executes a closure after an initial delay at a dynamic rate in the pool.

The rate includes the time spent running the closure. For example, if the return rate is 5 seconds and the closure takes 2 seconds to run, the closure will be run again 3 seconds after it completes.

Panics

If the closure panics, it will not be run again.

source

pub fn execute_with_fixed_delay<F>( &self, initial_delay: Duration, delay: Duration, f: F ) -> JobHandlewhere F: FnMut() + Send + 'static,

Executes a closure after an initial delay at a fixed rate in the pool.

In contrast to execute_at_fixed_rate, the execution time of the closure is not subtracted from the delay before it runs again. For example, if the delay is 5 seconds and the closure takes 2 seconds to run, the closure will run again 5 seconds after it completes.

Panics

If the closure panics, it will not be run again.

source

pub fn execute_with_dynamic_delay<F>( &self, initial_delay: Duration, f: F ) -> JobHandlewhere F: FnMut() -> Option<Duration> + Send + 'static,

Executes a closure after an initial delay at a dynamic rate in the pool.

In contrast to execute_at_dynamic_rate, the execution time of the closure is not subtracted from the returned delay before it runs again. For example, if the delay is 5 seconds and the closure takes 2 seconds to run, the closure will run again 5 seconds after it completes.

Panics

If the closure panics, it will not be run again.

Trait Implementations§

source§

impl Drop for ScheduledThreadPool

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.