docs

You are reading the docs for v0.1.0. Nabi 0.1.0 is no longer supported. Latest release: v0.1.3 →

core::par

On this page

data-parallel helpers, on the process's task executor (core::task): from async code on the worker it runs on, from sync code with the caller as a guest worker. Chunks are claimed from a shared counter by one job per worker.

Structs

ScopeSource

pub struct Scope

Spawns tasks that scope waits for.

  • pub fn spawn<T: Send>(self, f: fn() -> T + Send) -> ScopeHandle<T>§

    Source

    Run f on the parallel pool and return a handle to join its result. Under try_scope the task is cancelled when the scope is; every task is joined before the scope returns. Panics if called after the scope ended.

Trait implementations 1

ScopeHandleSource

pub struct ScopeHandle<T>

One Scope::spawned task.

  • pub fn join(self) -> T§

    Source

    Wait for the task; its result.

Trait implementations 1
  • impl<T> Debug for ScopeHandle<T>

TryScopeSource

pub struct TryScope<E>

The Scope of try_scope.

  • pub fn spawn<T: Send>(self, f: fn() throws (E) -> T + Send) -> TryScopeHandle<T, E>§

    Source

    Scope::spawn for a throwing f: its error cancels the scope.

  • pub fn is_cancelled(self) -> bool§

    Source

    Whether the scope was cancelled: a long task may poll this.

Trait implementations 1
  • impl<E> Debug for TryScope<E>

TryScopeHandleSource

pub struct TryScopeHandle<T, E>

One TryScope::spawned task.

  • pub fn join(self) throws (E) -> T§

    Source

    Wait for the task: its result, its error, or (cancelled before it ran) the scope's first error.

Trait implementations 1
  • impl<T, E> Debug for TryScopeHandle<T, E>

Functions

for_eachSource

pub fn for_each<I: IntoIterator<Item = T>, T: Send>(iter: I, f: fn(T) + Send + Sync)

Call f on every item, in parallel (order unspecified).

mapSource

pub fn map<I: IntoIterator<Item = T>, T: Send, U: Send>(iter: I, f: fn(T) -> U + Send + Sync) -> List<U>

f of every item, in the items' order.

foldSource

pub fn fold<I: IntoIterator<Item = T>, T: Send>(iter: I, init: T, f: fn(T, T) -> T + Send + Sync) -> T

Fold with an associative f: chunks fold in parallel, then init and the chunk results fold in order.

reduceSource

pub fn reduce<I: IntoIterator<Item = T>, T: Send>(iter: I, f: fn(T, T) -> T + Send + Sync) -> T | none

Combine the items with an associative f, as Iterator::reduce: chunks reduce in parallel, then the chunk results in order; none for no items.

filterSource

pub fn filter<I: IntoIterator<Item = T>, T: Send>(iter: I, pred: fn(T) -> bool + Send + Sync) -> List<T>

The items pred accepts, in order.

joinSource

pub fn join<T1: Send, T2: Send>(f1: fn() -> T1 + Send, f2: fn() -> T2 + Send) -> (T1, T2)

Run both at once; both results.

scopeSource

pub fn scope(f: fn(Scope))

Structured spawning: every task s.spawns has finished when scope returns.

try_scopeSource

pub fn try_scope<E: Send>(f: fn(TryScope<E>) throws (E)) throws (E)

scope whose body and tasks may throw. The first error cancels the scope: tasks that have not started never run (a running one finishes: a sync closure has no cancellation point), try_scope waits for the rest and throws that error.