Skip to main content

co_lines

Function co_lines 

Source
pub fn co_lines() -> CoLines
Available on crate feature process only.
Expand description

Create reader to access output line-by-line.

The items will be available for read as soon as they are piped from the child, without having to wait for the child to finish first.

Note that for small outputs, it’s usually better to simply use string() and call .lines() on the result.

§Example

use cu::pre::*;

let (child, mut lines) = cu::which("bash")?.command()
    .args(["-c", r#"for i in {1..5}; do echo "Line $i"; done"# ])
    .stdout(cu::pio::co_lines())
    .stdie_null()
    .co_spawn().await?;

let mut i = 1;
while let Some(line) = lines.next().await {
    let line = line?;
    assert_eq!(line, format!("Line {i}"));
    i+=1;
}

child.co_wait_nz().await?;