Flowync

Crates.io minimum rustc 1.61.0 CI Flowync documentation unsafe forbidden

Quick Example

```rust use flowync::{Flower, IOError}; type TestFlower = Flower;

fn fetch_things(id: usize) -> Result { let result = Ok::(format!("the flower with id: {} successfully completed fetching.", id)); let success = result?; Ok(success) }

fn main() { let flower: TestFlower = Flower::new(1); std::thread::spawn({ let handle = flower.handle(); // Activate handle.activate(); move || { for i in 0..10 { // Send current value through channel, will block the spawned thread // until the option value successfully being polled in the main thread. handle.send(i); // or handle.sendasync(i).await; can be used from any multithreaded async runtime, } let result = fetchthings(handle.id()); // Set result and then extract later. handle.set_result(result) } });

let mut exit = false;

loop {
    // Check if the flower is_active()
    // and will deactivate itself if the result value successfully received.
    if flower.is_active() {
        // another logic goes here...
        // e.g:
        // notify_loading_fn();

        flower
            .extract(|channel| {
                // Poll channel
                if let Some(value) = channel {
                    println!("{}", value);
                }
            })
            .finalize(|result| {
                match result {
                    Ok(value) => println!("{}", value),
                    Err(err_msg) => println!("{}", err_msg),
                }
                // Exit if finalized
                exit = true;
            });
    }

    if exit {
        break;
    }
}

} ```

More examples

can be found here: examples and here: eframe tokio (sync/async) integration example