use flowync::{
error::{Cause, IOError},
Flower,
};
type TestSimpleFlower = Flower<(), String>;
fn fetch_things(id: usize) -> Result<String, IOError> {
let result =
Ok::<String, IOError>(format!("the flower with id: {} successfully completed", id));
let success = result?;
Ok(success)
}
fn main() {
let flower: TestSimpleFlower = Flower::new(1);
std::thread::spawn({
let handle = flower.handle();
handle.activate();
move || {
let id = handle.id();
let result = fetch_things(id);
handle.set_result(result)
}
});
let mut exit = false;
loop {
if flower.is_active() {
flower.try_result(|result| {
match result {
Ok(value) => println!("{}", value),
Err(Cause::Suppose(msg)) => {
println!("{}", msg)
}
_ => (),
}
exit = true;
});
}
if exit {
break;
}
}
}