pub struct TaskPool { /* private fields */ }
Expand description
A pool of threads for running Task
s.
Implementations§
source§impl TaskPool
impl TaskPool
sourcepub fn global() -> &'static Self
pub fn global() -> &'static Self
sourcepub fn builder() -> TaskPoolBuilder
pub fn builder() -> TaskPoolBuilder
Creates a new TaskPoolBuilder
.
Examples
let task_pool = TaskPool::builder()
.num_threads(4)
.stack_size(1024 * 1024)
.thread_name("my-task-pool")
.build()
.expect("Failed to create task pool");
sourcepub fn thread_count(&self) -> usize
pub fn thread_count(&self) -> usize
Returns the number of threads in the pool.
sourcepub fn spawn<T>(
&self,
future: impl Future<Output = T> + Send + 'static
) -> Task<T> ⓘwhere
T: Send + 'static,
pub fn spawn<T>( &self, future: impl Future<Output = T> + Send + 'static ) -> Task<T> ⓘwhere T: Send + 'static,
Spawns a Task
in the thread pool.
sourcepub fn spawn_local<T>(
&self,
future: impl Future<Output = T> + 'static
) -> Task<T> ⓘwhere
T: 'static,
pub fn spawn_local<T>( &self, future: impl Future<Output = T> + 'static ) -> Task<T> ⓘwhere T: 'static,
Spawns a Task
in the thread local executor.