Flowync

Crates.io Flowync documentation CI

Quick Example

```rust use flowync::Flower;

fn main() { let flower = Flower::::new(1); std::thread::spawn({ let handle = flower.handle(); move || { // Start flowing to initialize. handle.startflowing(); 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.sendcurrent(i); // // Return error if the job is failure, for example: // if i >= 3 { // return handle.err("Err".tostring()); // } } // And return ok if the job successfully completed. return handle.ok("Ok".tostring()); } });

let mut exit = false;

loop {
    // This fn will deactivate itself if the result contains a value.
    // Note: this fn is non-blocking (won't block the current thread).
    flower.try_recv(
        |option| {
            if let Some(value) = option {
                println!("{}", value);
            }
        },
        |result| {
            match result {
                Ok(value) => {
                    println!("{}", value);
                }
                Err(e) => {
                    println!("{}", e);
                }
            }
            exit = true;
        },
    );

    if exit {
        break;
    }
}

} ```

More examples

can be found here here