Skip to main content

Module executor

Module executor 

Source
Expand description

Sandbox executor for both blocking and concurrent execution.

This module provides the unified API for sandbox execution:

  • Executor::run() - Blocking execution (single sandbox)
  • Executor::spawn() + poll() - Concurrent execution (multiple sandboxes)

§Blocking Example

use evalbox_sandbox::{Executor, Plan};

let output = Executor::run(Plan::new(["echo", "hello"]))?;
assert_eq!(output.stdout, b"hello\n");

§Concurrent Example

use evalbox_sandbox::{Executor, Plan, Event};

let mut executor = Executor::new()?;
let id = executor.spawn(Plan::new(["echo", "hello"]))?;

let mut events = Vec::new();
while executor.active_count() > 0 {
    executor.poll(&mut events, None)?;
    for event in events.drain(..) {
        match event {
            Event::Completed { id, output } => println!("Done: {:?}", output),
            Event::Stdout { id, data } => print!("{}", String::from_utf8_lossy(&data)),
            _ => {}
        }
    }
}

Structs§

Executor
SandboxId

Enums§

Event
Events emitted by the Executor.
ExecutorError
Error during sandbox execution.