async fn process_incoming_responses(
    proc_id: usize,
    mut mailbox: Mailbox,
    stdout_tx: mpsc::Sender<Vec<u8>>,
    stderr_tx: mpsc::Sender<Vec<u8>>,
    kill_tx: mpsc::Sender<()>,
) -> Result<(bool, Option<i32>), RemoteProcessError> {
    while let Some(res) = mailbox.next().await {
        // Check if any of the payload data is the termination
        let exit_status = res.payload.iter().find_map(|data| match data {
            ResponseData::ProcDone { id, success, code } if *id == proc_id => {
                Some((*success, *code))
            }
            _ => None,
        });

        // Next, check for stdout/stderr and send them along our channels
        // TODO: What should we do about unexpected data? For now, just ignore
        for data in res.payload {
            match data {
                ResponseData::ProcStdout { id, data } if id == proc_id => {
                    let _ = stdout_tx.send(data).await;
                }
                ResponseData::ProcStderr { id, data } if id == proc_id => {
                    let _ = stderr_tx.send(data).await;
                }
                _ => {}
            }
        }

        // If we got a termination, then exit accordingly
        if let Some((success, code)) = exit_status {
            // Flag that the other task should conclude
            let _ = kill_tx.try_send(());

            return Ok((success, code));
        }
    }

    // Flag that the other task should conclude
    let _ = kill_tx.try_send(());

    trace!("Process incoming channel closed");
    Err(RemoteProcessError::UnexpectedEof)
}
/// Helper function that loops, processing incoming stdout & stderr requests from a remote process
Helper function that loops, processing incoming stdout & stderr requests from a remote process
Helper function that loops processing incoming stdout & stderr requests from a remote process
async fn process_incoming_responses(
    proc_id: usize,
    mut mailbox: Mailbox,
    stdout_tx: mpsc::Sender<Vec<u8>>,
    stderr_tx: mpsc::Sender<Vec<u8>>,
    kill_tx: mpsc::Sender<()>,
) -> Result<(bool, Option<i32>), RemoteProcessError> {
    while let Some(res) = mailbox.next().await {
        // Check if any of the payload data is the termination
        let exit_status = res.payload.iter().find_map(|data| match data {
            ResponseData::ProcDone { id, success, code } if *id == proc_id => {
                Some((*success, *code))
            }
            _ => None,
        });
        // Next, check for stdout/stderr and send them along our channels
        // TODO: What should we do about unexpected data? For now, just ignore
        for data in res.payload {
            match data {
                ResponseData::ProcStdout { id, data } if id == proc_id => {
                    let _ = stdout_tx.send(data).await;
                }
                ResponseData::ProcStderr { id, data } if id == proc_id => {
                    let _ = stderr_tx.send(data).await;
                }
                _ => {}
            }
        }
        // If we got a termination, then exit accordingly
        if let Some((success, code)) = exit_status {
            // Flag that the other task should conclude
            let _ = kill_tx.try_send(());
            return Ok((success, code));
        }
    }
    // Flag that the other task should conclude
    let _ = kill_tx.try_send(());
    trace!("Process incoming channel closed");
    Err(RemoteProcessError::UnexpectedEof)
}
async fn process_incoming_responses ( proc_id : usize , mut mailbox : Mailbox , stdout_tx : mpsc :: Sender < Vec < u8 > > , stderr_tx : mpsc :: Sender < Vec < u8 > > , kill_tx : mpsc :: Sender < ( ) > , ) -> Result < ( bool , Option < i32 > ) , RemoteProcessError > { while let Some ( res ) = mailbox . next ( ) . await { // Check if any of the payload data is the termination let exit_status = res . payload . iter ( ) . find_map ( | data | match data { ResponseData :: ProcDone { id , success , code } if * id == proc_id => { Some ( ( * success , * code ) ) } _ => None , } ) ; // Next, check for stdout/stderr and send them along our channels // TODO: What should we do about unexpected data? For now, just ignore for data in res . payload { match data { ResponseData :: ProcStdout { id , data } if id == proc_id => { let _ = stdout_tx . send ( data ) . await ; } ResponseData :: ProcStderr { id , data } if id == proc_id => { let _ = stderr_tx . send ( data ) . await ; } _ => { } } } // If we got a termination, then exit accordingly if let Some ( ( success , code ) ) = exit_status { // Flag that the other task should conclude let _ = kill_tx . try_send ( ( ) ) ; return Ok ( ( success , code ) ) ; } } // Flag that the other task should conclude let _ = kill_tx . try_send ( ( ) ) ; trace ! ( " " ) ; Err ( RemoteProcessError :: UnexpectedEof ) }
Helper function that loops, processing incoming stdout & stderr requests from a remote process
Helper function that loops processing incoming stdout & stderr requests from a remote process
proc_id
usize
mailbox
Mailbox
stdout_tx
mpsc::Sender<Vec<u8>>
stderr_tx
mpsc::Sender<Vec<u8>>
kill_tx
mpsc::Sender<()>