use std::sync::{Arc, Mutex};
use std::thread;
use std::thread::sleep;
use std::time::Duration;
use conreg::target::*;
const HALF_A_SEC: Duration = Duration::from_millis(500);
const ONE_SEC: Duration = Duration::from_millis(1000);
fn main() {
let target = Arc::new(Mutex::new(TargetValue(0_isize)));
let target_clone = Arc::clone(&target);
let handle = thread::spawn(move || {
for _v in 1..7 {
{
let mut t = target_clone.lock().unwrap();
println!("Value {:?}", t.next());
}
sleep(HALF_A_SEC);
}
});
sleep(ONE_SEC);
{
let mut t = target.lock().unwrap();
t.set(1_isize);
}
sleep(ONE_SEC);
{
let mut t = target.lock().unwrap();
t.set(2_isize);
}
handle.join().unwrap();
}