Expand description
Streaming and async iteration support
This module provides async streaming capabilities similar to JavaScript’s
async iterators and stream handling in $.stream-utils.mjs.
§Usage
use command_stream::{StreamingRunner, OutputChunk};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let runner = StreamingRunner::new("yes hello");
// Stream output as it arrives
let mut stream = runner.stream();
let mut count = 0;
while let Some(chunk) = stream.next().await {
match chunk {
OutputChunk::Stdout(data) => {
print!("{}", String::from_utf8_lossy(&data));
count += 1;
if count >= 5 {
break;
}
}
OutputChunk::Stderr(data) => {
eprint!("{}", String::from_utf8_lossy(&data));
}
OutputChunk::Exit(code) => {
println!("Process exited with code: {}", code);
break;
}
}
}
Ok(())
}Structs§
- Output
Stream - Stream of output chunks from a process
- Streaming
Runner - A streaming process runner that allows async iteration over output
Enums§
- Output
Chunk - A chunk of output from a streaming process
Traits§
- Async
Iterator - Async iterator trait for output streams
- Into
Stream - Extension trait to convert ProcessRunner into a stream