Blocking variant of Receiver::try_iter needed


#1

My thread does its job in a loop: collect all pending signals, than process:

'mloop: loop {
  // wait for signal
  match rx.recv().unwrap() {
    MySignal::Stop => break 'mloop,
    // all other cases
  }
  
  // process all other signals
  match rx.try_iter() {
    MySignal::Stop => break 'mloop,
    // all other cases
  }

  // do some processing
}

The problem is a need to double the match with its body.
Am I doing this correctly? Unfortunately I do not find Receiver implementing function “block for a signal, but if there are more in a queue, iterate over them.”


#2

You could do this:

for signal in std::iter::once(rx.recv().unwrap()).chain(rx.try_iter()) {
    match signal {
        MySignal::Stop => ...
    }
}