https://opendal.apache.org/ logo
Thank you. Do you have any good examples with asyn...
# general
a
Thank you. Do you have any good examples with async? The one I came up with is a bit embarrasing:
Copy code
let builder = services::Dashmap::default();
    // Init an operator
    let op = Operator::new(builder)?
        // Init with logging layer enabled.
        .layer(LoggingLayer::default())
        .finish();
    debug!("operator: {op:?}");
    op.write("test", "test_string").await?;
    let op_arc = Arc::new(Mutex::new(op));
    let op_temp = op_arc.clone();
    let glob = Glob::new("*.md").unwrap().compile_matcher();
    let path = PathBuf::from("/Users/alexandermikhalev/NewDigitalMind");
    let (tx, rx) = crossbeam_channel::bounded::<DirEntry>(100);
    let stdout_thread = thread::spawn(move || async move {
        for dent in rx {
            if glob.is_match(dent.path()) {
                println!("{} is matched", dent.path().display());
                let path_clone = dent.path().to_owned();
                parse_into_operator(op_arc.clone(), &path_clone).await;
                println!("Completed file: {:?}", path_clone.display());
            }
        }
    });
    // FIXME: number of threads used is not the same as the number of cores
    let walker = WalkBuilder::new(path).threads(6).build_parallel();
    walker.run(|| {
        let tx = tx.clone();
        Box::new(move |result| {
            tx.send(DirEntry(result.unwrap())).unwrap();
            ignore::WalkState::Continue
        })
    });
    drop(tx);
    stdout_thread.join().unwrap().await;
    // Get object metadata.
    let storage = op_temp.lock().await;
    let meta = storage.stat("test").await;
    info!("meta: {:?}", meta);
2 Views