-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
I previously (0.4.1) used the sync API, where I could just do a let msg = rx.try_recv().unwrap(); and the unwrap would only fail if the other end disconnected.
My use case is that I have a producer thread and several consumer threads that are just waiting for messages.
How is the new API intended to be used? Currently I do something like the following:
loop {
let msg = match self.rx.try_recv() {
Ok(msg) => msg,
Err(channel::TryRecvError::Empty) => continue,
Err(channel::TryRecvError::Disconnected) => panic!("Sender disconnected"),
};
}On the receiver which seems to work, but uses full CPU, so probably I should add a sleep in the Empty branch:
loop {
let msg = match self.rx.try_recv() {
Ok(msg) => msg,
Err(channel::TryRecvError::Empty) => {
sleep(Duration::from_millis(1));
continue;
},
Err(channel::TryRecvError::Disconnected) => panic!("Sender disconnected"),
};
}Is this how the API should be used? Or should I use a different crate for my use case?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels