use flowync::{
error::{Cause, IOError},
Flower,
};
type TestFlower = Flower<u32, String>;
fn fetch_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)
}
fn main() {
let flower: TestFlower = Flower::new(1);
std::thread::spawn({
let handle = flower.handle();
handle.activate();
move || {
for i in 0..10 {
handle.send(i);
}
let result = fetch_things(handle.id());
handle.set_result(result)
}
});
let mut exit = false;
loop {
if flower.is_active() {
flower
.poll(|channel| {
if let Some(value) = channel {
println!("{}", value);
}
})
.finalize(|result| {
match result {
Ok(value) => println!("{}", value),
Err(Cause::Suppose(msg)) => {
println!("{}", msg)
}
Err(Cause::Panicked(_msg)) => {
}
}
exit = true;
});
}
if exit {
break;
}
}
}