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(|s| {
9        let stdin = s.read_stdin::<f64>();
10        let stdout = s.write_stdout::<f64>();
11        s.spawn(sqrt(stdin, stdout));
12    })
13    .await
14}
15
16/// A block that computes the square root of input numbers.
17async fn sqrt(mut inputs: Inputs<f64>, outputs: Outputs<f64>) -> Result {
18    while let Some(input) = inputs.recv().await? {
19        let output = input.sqrt();
20        outputs.send(output).await?;
21    }
22    Ok(())
23}