Struct entangled::ThreadPool[][src]

pub struct ThreadPool { /* fields omitted */ }

A thread pool for executing futures.

Drives given futures to completion.

Implementations

impl ThreadPool[src]

pub fn new(descriptor: ThreadPoolDescriptor) -> Result<Self, Error>[src]

Create a new ThreadPool. Thread pools can be freely cloned.

How to provide a custom handler

use entangled::*;

let descriptor = ThreadPoolDescriptor {
    num_threads: 0,
    start_handler: Some(Box::new(|index| {
        println!("Thread {} is starting", index);
    })),
    ..Default::default()
};

let pool = ThreadPool::new(descriptor).unwrap();

pub fn scope<'scope, S, R>(&self, s: S) -> Vec<R> where
    S: FnOnce(&mut Scope<'scope, R>) + 'scope + Send,
    R: Send + 'static, 
[src]

Creates a “fork-join” scope s and invokes the closure with a reference to s. This closure can then spawn futures into s. When the closure returns, it will block until all futures that have been spawned into s complete.

In general, spawned futures may access stack data in place that outlives the scope itself. Other data must be fully owned by the spawned future.

pub fn spawn<T>(
    &self,
    future: impl Future<Output = T> + Send + 'static
) -> Task<T> where
    T: Send + 'static, 
[src]

Spawns a static future onto the thread pool. The returned Task is a future. It can also be cancelled and “detached” allowing it to continue running without having to be polled by the end-user.

Trait Implementations

impl Clone for ThreadPool[src]

impl Debug for ThreadPool[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.