Function blocks_iterator::par_iter

source ·
pub fn par_iter<STATE, PREPROC, TASK, DATA>(
    config: Config,
    state: Arc<STATE>,
    pre_processing: PREPROC,
    task: TASK
)where
    PREPROC: Fn(BlockExtra) -> Vec<DATA> + 'static + Send,
    TASK: Fn(DATA, Arc<STATE>) -> bool + 'static + Send + Sync,
    DATA: 'static + Send,
    STATE: 'static + Send + Sync,
👎Deprecated: you can get better and composable results by concateneting method on iter like blocks_iterator::iter(config).flat_map(PREPROC).par_bridge().for_each(TASK)
Expand description

par_iter is used when the task to be performed on the blockchain is more costly than iterating the blocks. For example verifying the spending conditions in the blockchain. like crate::iter() accepts configuration parameters via the Config struct. A PREPROC closure has to be provided, this process a single block and produce a Vec of user defined struct DATA. A TASK closure accepts the DATA struct and a shared STATE and it is executed in a concurrent way. The TASK closure returns a bool which indicates if the execution should be terminated. Note that access to STATE in TASK should be done carefully otherwise the contention would reduce the speed of execution.