sqrt/
sqrt.rs

1// This is free and unencumbered software released into the public domain.
2
3use async_flow::{Inputs, Outputs, Result, System};
4
5/// cargo run --example sqrt
6#[tokio::main(flavor = "current_thread")]
7pub async fn main() -> Result {
8    System::run(|system| {
9        let stdin = system.read_stdin::<f64>();
10        let stdout = system.write_stdout::<f64>();
11        system.spawn(sqrt(stdin, stdout));
12    })
13    .await
14}
15
16async fn sqrt(mut inputs: Inputs<f64>, outputs: Outputs<f64>) -> Result {
17    while let Some(input) = inputs.recv().await? {
18        let output = input.sqrt();
19        outputs.send(output).await?;
20    }
21    Ok(())
22}