rok::core::par
rok::core::par - data-parallel helpers (stdlib spec 2.19), on the
process's task executor (rok::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
Scope
pub struct ScopeSpawns tasks that scope waits for.
pub fn spawn<T: Send>(self, f: fn() -> T + Send) -> ScopeHandle<T>
ScopeHandle
pub struct ScopeHandle<T>One Scope::spawned task.
pub fn join(self) -> TWait for the task; its result.
TryScope
pub struct TryScope<E>The Scope of try_scope.
pub fn spawn<T: Send>(self, f: fn() throws (E) -> T + Send) -> TryScopeHandle<TScope::spawnfor a throwingf: its error cancels the scope.pub fn is_cancelled(self) -> boolWhether the scope was cancelled: a long task may poll this.
TryScopeHandle
pub struct TryScopeHandle<TOne TryScope::spawned task.
Functions
for_each
pub fn for_each<I: IntoIterator<Item = T>Call f on every item, in parallel (order unspecified).
map
pub fn map<I: IntoIterator<Item = T>f of every item, in the items' order.
reduce
pub fn reduce<T: Send + Sync>(iter: List<T>, init: T, f: fn(T, T) -> T + Send + Sync) -> TFold with an associative f (2.19.4): chunks fold in parallel, then
init and the chunk results fold in order.
filter
pub fn filter<T: Send>(iter: List<T>, pred: fn(T) -> bool + Send + Sync) -> List<T>The items pred accepts, in order.
join
pub fn join<T1: SendRun both at once; both results.
scope
pub fn scope(f: fn(Scope))Structured spawning (2.19.3): every task s.spawns has finished
when scope returns.
try_scope
pub fn try_scope<E: Send>(f: fn(TryScope<E>) throws (E)) throws (E)scope whose body and tasks may throw (2.19.3: "an exception cancels
the children"). 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. Not in spec 2.19, whose scope takes a non-throwing
fn(Scope).