progressive icon indicating copy to clipboard operation
progressive copied to clipboard

Support rayon

Open udalrich opened this issue 3 years ago • 0 comments

It does not seem to be possible to use progressive with rayon's par_iter. I would like to do something like

use progressive::progress;
use rayon::prelude::*;
use std::{thread, time};
fn main() {
    let v: Vec<u64> = (0..10).collect();

    progress(
        v.par_iter()
            .map(|n| time::Duration::from_secs(n.to_owned()))
            .inspect(|n| {
                thread::sleep(n.to_owned());
            }),
    )
    .for_each(|n| {
        println!("Slept {:?}", n);
    });

    println!("Results:")
}

but that does not compile because par_iter and the related functions do not return an Iterator.

Ideally, the above code would produce a progress bar that updates once a second, going from 0 to 11 units of work completed.

I am not familiar with the details of how rayon works, so this is probably at least more complicated than supporting Iterator and could easily be very difficult/impossible.

udalrich avatar Oct 11 '21 21:10 udalrich