Skip to content

pimalaya/process

Repository files navigation

Process flows Documentation Matrix

Rust I/O-free library to manage processes.

Design

This library does not perform I/O the usual way. It relies instead on 3 concepts:

Flow

The flow is an I/O-free, composable and iterable state machine that emits I/O requests. A flow is considered terminated when it does not emit I/O requests anymore.

See available flows at ./src/flows.

Handler

The I/O handler contains all the I/O logic, and is responsible for processing I/O requests. It takes input from the flow, performs I/O, then puts the output back inside the flow.

See available handlers at ./src/handlers.

Loop

The loop is the glue between the flow and the I/O handler. It makes the flow progress while allowing handlers to process I/O.

Examples

See complete examples at ./examples.

Spawn then wait for exit status synchronously

use process_flows::{flows::SpawnThenWait, handlers::std::handle, Command};

let mut command = Command::new("ls");
command.arg("-al");
command.arg("/tmp");

let mut spawn = SpawnThenWait::new(command);
let status = loop {
    match spawn.next() {
        Ok(status) => break status,
        Err(io) => handle(&mut spawn, io).unwrap(),
    }
}

Spawn then wait for output asynchronously

use process_flows::{flows::SpawnThenWaitWithOutput, handlers::tokio::handle, Command};

let mut command = Command::new("ls");
command.arg("-al");
command.arg("/tmp");

let mut spawn = SpawnThenWaitWithOutput::new(command);
let output = loop {
    match spawn.next() {
        Ok(output) => break output,
        Err(io) => handle(&mut spawn, io).await.unwrap(),
    }
}

More

Have a look at bigger projects built on the top of process flows:

Sponsoring

nlnet

Special thanks to the NLnet foundation and the European Commission that helped the project to receive financial support from various programs:

If you appreciate the project, feel free to donate using one of the following providers:

GitHub Ko-fi Buy Me a Coffee Liberapay thanks.dev PayPal