| Crates.io | async-flow |
| lib.rs | async-flow |
| version | 0.1.1 |
| created_at | 2025-05-24 10:24:05.111918+00 |
| updated_at | 2026-01-22 17:52:36.240459+00 |
| description | Async abstractions for flow-based programming (FBP). |
| homepage | https://async-flow.rs |
| repository | https://github.com/artob/async-flow |
| max_upload_size | |
| id | 1687276 |
| size | 54,980 |
"Τὰ πάντα ῥεῖ καὶ οὐδὲν μένει" — Heraclitus
Async abstractions for flow-based programming (FBP) in Rust. This crate can be used to implement dataflow systems consisting of reusable, interconnected blocks that process arbitrary messages.
[!TIP] 🚧 We are building in public. This is presently under heavy construction.
[Features] | [Prerequisites] | [Installation] | [Examples] | [Reference] | [Development]
cargo add async-flow
use async_flow::*;
use async_flow::{Inputs, Outputs, Result, System};
#[tokio::main(flavor = "current_thread")]
pub async fn main() -> Result {
System::run(|s| {
let stdin = s.read_stdin::<f64>();
let stdout = s.write_stdout::<f64>();
s.spawn(sqrt(stdin, stdout));
})
.await
}
/// A block that computes the square root of input numbers.
async fn sqrt(mut inputs: Inputs<f64>, outputs: Outputs<f64>) -> Result {
while let Some(input) = inputs.recv().await? {
let output = input.sqrt();
outputs.send(output).await?;
}
Ok(())
}
split_string blockuse async_flow::{Inputs, Outputs, Result};
/// A block that splits input strings based on a delimiter.
async fn split_string(delim: &str, mut inputs: Inputs<String>, outputs: Outputs<String>) -> Result {
while let Some(input) = inputs.recv().await? {
for output in input.split(delim) {
outputs.send(output.into()).await?;
}
}
Ok(())
}
add_ints blockuse async_flow::{Inputs, Outputs, Result};
/// A block that outputs the sums of input numbers.
async fn add_ints(mut lhs: Inputs<i64>, mut rhs: Inputs<i64>, sums: Outputs<i64>) -> Result {
loop {
let (a, b) = tokio::try_join!(lhs.recv(), rhs.recv())?;
match (a, b) {
(Some(a), Some(b)) => sums.send(a + b).await?,
_ => break,
}
}
Ok(())
}
System: A collection of blocks that are connected together. Systems are the top-level entities in dataflow programs.
Block: An encapsulated system component that processes messages. Blocks are the autonomous units of computation in a system.
Port: A named connection point on a block that sends or receives messages. Ports are the only interfaces through which blocks communicate with each other.
Message: A unit of data that flows between blocks in a system, from port
to port. Any Rust type that implements the Send + Sync + 'static traits can
be used as a message.
git clone https://github.com/artob/async-flow.git