Function par_stream::try_par_unfold_blocking
source · [−]pub fn try_par_unfold_blocking<Item, Error, State, P, F>(
params: P,
init: State,
f: F
) -> TryParUnfoldBlocking<Item, Error> where
F: 'static + FnMut(usize, State) -> Result<Option<(Item, State)>, Error> + Send + Clone,
Item: 'static + Send,
Error: 'static + Send,
State: 'static + Send + Clone,
P: Into<ParParams>,
Expand description
Produce stream elements from a fallible parallel asynchronous task.
This function spawns a set of parallel workers. Each worker produces and places
items to an output buffer. The worker pool size and buffer size is determined by
params
.
Each worker receives a copy of initialized state init
, then iteratively calls the function
f(worker_index, State) -> Result<Option<(output, State)>, Error>
, which updates the state
and produces an output item.
If a worker receives an error Err(_)
, the error is produced in output stream and the stream halts for ever.
If a worker receives a Ok(None)
, the worker with that worker index will halt, but it does not halt
the other workers. The output stream terminates after every worker halts.