pub(super) async fn process(
    session: WezSession,
    state: Arc<Mutex<State>>,
    req: Request,
    tx: mpsc::Sender<Response>,
) -> Result<(), mpsc::error::SendError<Response>> {
    async fn inner<F>(
        session: WezSession,
        state: Arc<Mutex<State>>,
        data: RequestData,
        reply: F,
    ) -> io::Result<Outgoing>
    where
        F: FnMut(Vec<ResponseData>) -> ReplyRet + Clone + Send + 'static,
    {
        match data {
            RequestData::FileRead { path } => file_read(session, path).await,
            RequestData::FileReadText { path } => file_read_text(session, path).await,
            RequestData::FileWrite { path, data } => file_write(session, path, data).await,
            RequestData::FileWriteText { path, text } => file_write(session, path, text).await,
            RequestData::FileAppend { path, data } => file_append(session, path, data).await,
            RequestData::FileAppendText { path, text } => file_append(session, path, text).await,
            RequestData::DirRead {
                path,
                depth,
                absolute,
                canonicalize,
                include_root,
            } => dir_read(session, path, depth, absolute, canonicalize, include_root).await,
            RequestData::DirCreate { path, all } => dir_create(session, path, all).await,
            RequestData::Remove { path, force } => remove(session, path, force).await,
            RequestData::Copy { src, dst } => copy(session, src, dst).await,
            RequestData::Rename { src, dst } => rename(session, src, dst).await,
            RequestData::Exists { path } => exists(session, path).await,
            RequestData::Metadata {
                path,
                canonicalize,
                resolve_file_type,
            } => metadata(session, path, canonicalize, resolve_file_type).await,
            RequestData::ProcSpawn {
                cmd,
                args,
                detached,
            } => proc_run(session, state, reply, cmd, args, detached).await,
            RequestData::ProcKill { id } => proc_kill(session, state, id).await,
            RequestData::ProcStdin { id, data } => proc_stdin(session, state, id, data).await,
            RequestData::ProcList {} => proc_list(session, state).await,
            RequestData::SystemInfo {} => system_info(session).await,
        }
    }

    let reply = {
        let origin_id = req.id;
        let tenant = req.tenant.clone();
        let tx_2 = tx.clone();
        move |payload: Vec<ResponseData>| -> ReplyRet {
            let tx = tx_2.clone();
            let res = Response::new(tenant.to_string(), origin_id, payload);
            Box::pin(async move { tx.send(res).await.is_ok() })
        }
    };

    // Build up a collection of tasks to run independently
    let mut payload_tasks = Vec::new();
    for data in req.payload {
        let state_2 = Arc::clone(&state);
        let reply_2 = reply.clone();
        let session = session.clone();
        payload_tasks.push(tokio::spawn(async move {
            match inner(session, state_2, data, reply_2).await {
                Ok(outgoing) => outgoing,
                Err(x) => Outgoing::from(ResponseData::from(x)),
            }
        }));
    }

    // Collect the results of our tasks into the payload entries
    let mut outgoing: Vec<Outgoing> = future::join_all(payload_tasks)
        .await
        .into_iter()
        .map(|x| match x {
            Ok(outgoing) => outgoing,
            Err(x) => Outgoing::from(ResponseData::from(x)),
        })
        .collect();

    let post_hooks: Vec<PostHook> = outgoing
        .iter_mut()
        .filter_map(|x| x.post_hook.take())
        .collect();

    let payload = outgoing.into_iter().map(|x| x.data).collect();
    let res = Response::new(req.tenant, req.id, payload);
    // Send out our primary response from processing the request
    let result = tx.send(res).await;

    // Invoke all post hooks
    for hook in post_hooks {
        hook();
    }

    result
}
/// Processes the provided request, sending replies using the given sender
Processes the provided request, sending replies using the given sender
Processes the provided request sending replies using the given sender
pub(super) async fn process(
    session: WezSession,
    state: Arc<Mutex<State>>,
    req: Request,
    tx: mpsc::Sender<Response>,
) -> Result<(), mpsc::error::SendError<Response>> {
    async fn inner<F>(
        session: WezSession,
        state: Arc<Mutex<State>>,
        data: RequestData,
        reply: F,
    ) -> io::Result<Outgoing>
    where
        F: FnMut(Vec<ResponseData>) -> ReplyRet + Clone + Send + 'static,
    {
        match data {
            RequestData::FileRead { path } => file_read(session, path).await,
            RequestData::FileReadText { path } => file_read_text(session, path).await,
            RequestData::FileWrite { path, data } => file_write(session, path, data).await,
            RequestData::FileWriteText { path, text } => file_write(session, path, text).await,
            RequestData::FileAppend { path, data } => file_append(session, path, data).await,
            RequestData::FileAppendText { path, text } => file_append(session, path, text).await,
            RequestData::DirRead {
                path,
                depth,
                absolute,
                canonicalize,
                include_root,
            } => dir_read(session, path, depth, absolute, canonicalize, include_root).await,
            RequestData::DirCreate { path, all } => dir_create(session, path, all).await,
            RequestData::Remove { path, force } => remove(session, path, force).await,
            RequestData::Copy { src, dst } => copy(session, src, dst).await,
            RequestData::Rename { src, dst } => rename(session, src, dst).await,
            RequestData::Exists { path } => exists(session, path).await,
            RequestData::Metadata {
                path,
                canonicalize,
                resolve_file_type,
            } => metadata(session, path, canonicalize, resolve_file_type).await,
            RequestData::ProcSpawn {
                cmd,
                args,
                detached,
            } => proc_run(session, state, reply, cmd, args, detached).await,
            RequestData::ProcKill { id } => proc_kill(session, state, id).await,
            RequestData::ProcStdin { id, data } => proc_stdin(session, state, id, data).await,
            RequestData::ProcList {} => proc_list(session, state).await,
            RequestData::SystemInfo {} => system_info(session).await,
        }
    }
    let reply = {
        let origin_id = req.id;
        let tenant = req.tenant.clone();
        let tx_2 = tx.clone();
        move |payload: Vec<ResponseData>| -> ReplyRet {
            let tx = tx_2.clone();
            let res = Response::new(tenant.to_string(), origin_id, payload);
            Box::pin(async move { tx.send(res).await.is_ok() })
        }
    };
    // Build up a collection of tasks to run independently
    let mut payload_tasks = Vec::new();
    for data in req.payload {
        let state_2 = Arc::clone(&state);
        let reply_2 = reply.clone();
        let session = session.clone();
        payload_tasks.push(tokio::spawn(async move {
            match inner(session, state_2, data, reply_2).await {
                Ok(outgoing) => outgoing,
                Err(x) => Outgoing::from(ResponseData::from(x)),
            }
        }));
    }
    // Collect the results of our tasks into the payload entries
    let mut outgoing: Vec<Outgoing> = future::join_all(payload_tasks)
        .await
        .into_iter()
        .map(|x| match x {
            Ok(outgoing) => outgoing,
            Err(x) => Outgoing::from(ResponseData::from(x)),
        })
        .collect();
    let post_hooks: Vec<PostHook> = outgoing
        .iter_mut()
        .filter_map(|x| x.post_hook.take())
        .collect();
    let payload = outgoing.into_iter().map(|x| x.data).collect();
    let res = Response::new(req.tenant, req.id, payload);
    // Send out our primary response from processing the request
    let result = tx.send(res).await;
    // Invoke all post hooks
    for hook in post_hooks {
        hook();
    }
    result
}
pub ( super ) async fn process ( session : WezSession , state : Arc < Mutex < State > > , req : Request , tx : mpsc :: Sender < Response > , ) -> Result < ( ) , mpsc :: error :: SendError < Response > > { async fn inner < F > ( session : WezSession , state : Arc < Mutex < State > > , data : RequestData , reply : F , ) -> io :: Result < Outgoing > where F : FnMut ( Vec < ResponseData > ) -> ReplyRet + Clone + Send + ' static , { match data { RequestData :: FileRead { path } => file_read ( session , path ) . await , RequestData :: FileReadText { path } => file_read_text ( session , path ) . await , RequestData :: FileWrite { path , data } => file_write ( session , path , data ) . await , RequestData :: FileWriteText { path , text } => file_write ( session , path , text ) . await , RequestData :: FileAppend { path , data } => file_append ( session , path , data ) . await , RequestData :: FileAppendText { path , text } => file_append ( session , path , text ) . await , RequestData :: DirRead { path , depth , absolute , canonicalize , include_root , } => dir_read ( session , path , depth , absolute , canonicalize , include_root ) . await , RequestData :: DirCreate { path , all } => dir_create ( session , path , all ) . await , RequestData :: Remove { path , force } => remove ( session , path , force ) . await , RequestData :: Copy { src , dst } => copy ( session , src , dst ) . await , RequestData :: Rename { src , dst } => rename ( session , src , dst ) . await , RequestData :: Exists { path } => exists ( session , path ) . await , RequestData :: Metadata { path , canonicalize , resolve_file_type , } => metadata ( session , path , canonicalize , resolve_file_type ) . await , RequestData :: ProcSpawn { cmd , args , detached , } => proc_run ( session , state , reply , cmd , args , detached ) . await , RequestData :: ProcKill { id } => proc_kill ( session , state , id ) . await , RequestData :: ProcStdin { id , data } => proc_stdin ( session , state , id , data ) . await , RequestData :: ProcList { } => proc_list ( session , state ) . await , RequestData :: SystemInfo { } => system_info ( session ) . await , } } let reply = { let origin_id = req . id ; let tenant = req . tenant . clone ( ) ; let tx_2 = tx . clone ( ) ; move | payload : Vec < ResponseData > | -> ReplyRet { let tx = tx_2 . clone ( ) ; let res = Response :: new ( tenant . to_string ( ) , origin_id , payload ) ; Box :: pin ( async move { tx . send ( res ) . await . is_ok ( ) } ) } } ; // Build up a collection of tasks to run independently let mut payload_tasks = Vec :: new ( ) ; for data in req . payload { let state_2 = Arc :: clone ( & state ) ; let reply_2 = reply . clone ( ) ; let session = session . clone ( ) ; payload_tasks . push ( tokio :: spawn ( async move { match inner ( session , state_2 , data , reply_2 ) . await { Ok ( outgoing ) => outgoing , Err ( x ) => Outgoing :: from ( ResponseData :: from ( x ) ) , } } ) ) ; } // Collect the results of our tasks into the payload entries let mut outgoing : Vec < Outgoing > = future :: join_all ( payload_tasks ) . await . into_iter ( ) . map ( | x | match x { Ok ( outgoing ) => outgoing , Err ( x ) => Outgoing :: from ( ResponseData :: from ( x ) ) , } ) . collect ( ) ; let post_hooks : Vec < PostHook > = outgoing . iter_mut ( ) . filter_map ( | x | x . post_hook . take ( ) ) . collect ( ) ; let payload = outgoing . into_iter ( ) . map ( | x | x . data ) . collect ( ) ; let res = Response :: new ( req . tenant , req . id , payload ) ; // Send out our primary response from processing the request let result = tx . send ( res ) . await ; // Invoke all post hooks for hook in post_hooks { hook ( ) ; } result }
Processes the provided request, sending replies using the given sender
Processes the provided request sending replies using the given sender
session
WezSession
state
Arc<Mutex<State>>
req
Request
tx
mpsc::Sender<Response>