pub fn try_par_unfold<Item, Error, State, P, F, Fut>(
    params: P,
    init: State,
    f: F
) -> TryParUnfold<Item, Error> where
    P: Into<ParParams>,
    F: 'static + FnMut(usize, State) -> Fut + Send + Clone,
    Fut: 'static + Future<Output = Result<Option<(Item, State)>, Error>> + Send,
    State: 'static + Send + Clone,
    Item: 'static + Send,
    Error: 'static + Send
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) -> Fut. The Fut is a future that returns Result<Option<(output, State)>, Error>. The future 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.