Skip to content

Repository files navigation

Flowync

Crates.iominimum rustc 1.60.0+CIFlowync documentationunsafe forbidden

Quick Example

use flowync::{error::{Cause,IOError},Flower};typeTestFlower = Flower<u32,String>;fnfetch_things(id:usize) -> Result<String,IOError>{let result = Ok::<String,IOError>(format!("the flower with id: {} successfully completed fetching.",
id
));let success = result?;Ok(success)}fnmain(){let flower:TestFlower = Flower::new(1);
std::thread::spawn({let handle = flower.handle();// Activate
handle.activate();move || {for i in0..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.send_async(i).await; can be used from any multithreaded async runtime,}let result = fetch_things(handle.id());// Set result and then extract later.
handle.set_result(result)}});letmut 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
.poll(|channel| {ifletSome(value) = channel {println!("{}", value);}}).finalize(|result| {match result {Ok(value) => println!("{}", value),Err(Cause::Suppose(msg)) => {println!("{}", msg)}Err(Cause::Panicked(_msg)) => {// Handle things if stuff unexpectedly panicked at runtime.}}// Exit if finalized
exit = true;});}if exit {break;}}}

More examples

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

About

A simple utility for multithreading a/synchronization

Resources

Stars

23 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages