/// Selects the first active session. Receives from the selected session, and
/// removes the endpoint from the input vector. Returns the received value and
/// the continuation of the selected session.
Selects the first active session. Receives from the selected session, and
removes the endpoint from the input vector. Returns the received value and
the continuation of the selected session.
Selects the first active session . Receives from the selected session and removes the endpoint from the input vector . Returns the received value and the continuation of the selected session .
pub fn select_mut<T, S>(rs: &mut Vec<Recv<T, S>>) -> Result<(T, S), Box<dyn Error>>
where
    T: marker::Send,
    S: Session,
{
    if rs.is_empty() {
        Err(Box::new(SelectError::EmptyVec))
    } else {
        let (index, res) = {
            let mut sel = Select::new();
            let iter = rs.iter();
            for r in iter {
                sel.recv(&r.channel);
            }
            loop {
                let index = sel.ready();
                let res = rs[index].channel.try_recv();
                if let Err(e) = res {
                    if e.is_empty() {
                        continue;
                    }
                }
                break (index, res);
            }
        };
        let _ = rs.swap_remove(index);
        match res {
            Ok(res) => Ok(res),
            Err(e) => Err(Box::new(e)),
        }
    }
}
pub fn select_mut < T , S > ( rs : & mut Vec < Recv < T , S > > ) -> Result < ( T , S ) , Box < dyn Error > > where T : marker :: Send , S : Session , { if rs . is_empty ( ) { Err ( Box :: new ( SelectError :: EmptyVec ) ) } else { let ( index , res ) = { let mut sel = Select :: new ( ) ; let iter = rs . iter ( ) ; for r in iter { sel . recv ( & r . channel ) ; } loop { let index = sel . ready ( ) ; let res = rs [ index ] . channel . try_recv ( ) ; if let Err ( e ) = res { if e . is_empty ( ) { continue ; } } break ( index , res ) ; } } ; let _ = rs . swap_remove ( index ) ; match res { Ok ( res ) => Ok ( res ) , Err ( e ) => Err ( Box :: new ( e ) ) , } } }
Selects the first active session.
Selects the first active session .
rs
&mut Vec<Recv<T, S>>