Crossbeam select with recv_timeout

I'm writing code with producers/consumers and I want the consumer to shut down if there is no progress (maybe all the producers have panicked).
For that I was using recv_timeout. But later I had to add select! to print stats periodically.

Now the problem: it looks like there is no way to use recv_timeout or recv_deadline when using select! macro. There is default but (as far as I understood) it works for all the select and not for particular recv.

Any known workarounds? Or maybe I misuse select and there is a way to solve the problem in a different way?

    let timer_receiver = tick(Duration::from_millis(10 as u64));
    Builder::new()
        .name("Consumer".to_string())
        .spawn(move || {
            loop {
                select! {
                    recv(receiver) -> msg => { // here I cannot do a-la recv_timeout(Duration::from_millis(1000))
                        match msg {
                            Ok((msg, len)) => {
                                println!("Consuming {}", msg);
                            }
                            // And hence later I cannot do the following:
                            //Err(RecvTimeoutError::Timeout) => {
                            //        println!("No progress, stop now");
                            //        break;
                            //}
                            _ => panic!("Unexpected error"),
                        },
                        recv(timer_receiver) -> _ => {
                            println!("print stats");
                        }
                }
            }
        })
        .unwrap()
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.