I'm using the discord crate, which uses event loops. I need to check for events concurrently, while I am taking user input:
let clone = context.clone();
thread::spawn(
move || loop {
match clone.lock().unwrap().gateway.recv_event() {
Ok(event) => {
// println!("Updating state: {:?}", event);
clone.lock().unwrap().state.update(&event)
},
Err(err) => {
stderr!("Error receiving: {}", err);
},
}
}
);
This doesn't work because it stays locked... So what about
println!("Locking");
let mut gateway = {
&mut clone.lock().unwrap().gateway
};
println!("Unlocked? {:?}", clone);
match gateway.recv_event() {
Ok(event) => {
This also doesn't seem to work:
Locking
Unlocked? Mutex { <locked> }
How would this be solved?
It occurred to me it might just be best if there was a way to access to mutex's contents without locking.