use flowync::{
error::{Compact, IOError},
CompactFlower,
};
#[allow(dead_code)]
enum ErrMessage {
Segfault(String),
Other,
}
type TestCompactFlower = CompactFlower<u32, String, ErrMessage>;
fn fetch_things(id: usize) -> Result<String, IOError> {
let result = Ok::<String, IOError>(format!(
"the compact flower with id: {} successfully completed fetching.",
id
));
let success = result?;
Ok(success)
}
fn main() {
let compact_flower: TestCompactFlower = CompactFlower::new(1);
std::thread::spawn({
let handle = compact_flower.handle();
handle.activate();
move || {
for i in 0..10 {
handle.send(i);
}
match fetch_things(handle.id()) {
Ok(value) => {
handle.success(value);
}
Err(e) => handle.error(ErrMessage::Segfault(e.to_string())),
}
}
});
let mut exit = false;
loop {
if compact_flower.is_active() {
compact_flower
.poll(|channel| {
if let Some(value) = channel {
println!("{}", value);
}
})
.finalize(|result| {
match result {
Ok(value) => println!("{}", value),
Err(Compact::Suppose(ErrMessage::Segfault(msg))) => {
println!("{}", msg)
}
Err(Compact::Suppose(err_msg)) => {
if let ErrMessage::Other = err_msg {
}
}
Err(Compact::Panicked(_msg)) => {
}
}
exit = true;
});
}
if exit {
break;
}
}
}