[−][src]Struct easy_parallel::Parallel
A builder that runs closures in parallel.
Implementations
impl<'a, T> Parallel<'a, T>[src]
pub fn new() -> Parallel<'a, T>[src]
Creates a builder for running closures in parallel.
Examples
use easy_parallel::Parallel; let p = Parallel::<()>::new();
pub fn add<F>(self, f: F) -> Parallel<'a, T> where
F: FnOnce() -> T + Send + 'a,
T: Send + 'a, [src]
F: FnOnce() -> T + Send + 'a,
T: Send + 'a,
Adds a closure to the list.
Examples
use easy_parallel::Parallel; Parallel::new() .add(|| println!("hello from a thread")) .run();
pub fn each<A, I, F>(self, iter: I, f: F) -> Parallel<'a, T> where
I: IntoIterator<Item = A>,
F: FnOnce(A) -> T + Clone + Send + 'a,
A: Send + 'a,
T: Send + 'a, [src]
I: IntoIterator<Item = A>,
F: FnOnce(A) -> T + Clone + Send + 'a,
A: Send + 'a,
T: Send + 'a,
Adds a cloned closure for each item in an iterator.
Each clone of the closure takes an item as an argument.
Examples
use easy_parallel::Parallel; Parallel::new() .each(0..5, |i| println!("hello from thread #{}", i)) .run();
pub fn run(self) -> Vec<T> where
T: Send + 'a, [src]
T: Send + 'a,
Spawns a thread for each closure and collects their results.
Results are collected in the order in which threads completed.
If a closure panics, panicking will resume in the main thread after all threads are joined.
Examples
use easy_parallel::Parallel; use std::thread; use std::time::Duration; let res = Parallel::new() .each(0..5, |i| { thread::sleep(Duration::from_secs(5 - i)); i }) .run(); // Threads finish in reverse order because of how they sleep. assert_eq!(res, [4, 3, 2, 1, 0]);
Trait Implementations
Auto Trait Implementations
impl<'a, T> !RefUnwindSafe for Parallel<'a, T>
impl<'a, T> Send for Parallel<'a, T>
impl<'a, T> !Sync for Parallel<'a, T>
impl<'a, T> Unpin for Parallel<'a, T>
impl<'a, T> !UnwindSafe for Parallel<'a, T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,