Expand description
Foundational async primitives for Rust – timers, networking utilities, and common async building blocks.
This crate is runtime-agnostic: it focuses on low-level primitives that can be plugged into your own executor or existing async ecosystem.
§Modules
timer– high-level timer abstraction for scheduling waits and handling many concurrent timers efficiently.net– async wrappers around non-asyncmiotypes (TcpStream,UdpSocket, event listener, timeouts). Enabled by thenetfeature.common– utilities such ascommon::ready_future::ReadyFutureandcommon::ready_observable::ReadyObservablefor composing async workflows.
§Quick start
Basic timer usage:
use async_foundation::timer::timer::Timer;
use futures::executor::block_on;
use std::time::Duration;
let mut timer = Timer::new();
block_on(async {
// Wait for 100ms
timer.wait(Duration::from_millis(100)).await;
});TCP client using the async TcpStream wrapper:
use async_foundation::net::tcp_stream::TcpStream;
use futures::executor::block_on;
use futures::{AsyncReadExt, AsyncWriteExt};
block_on(async {
let mut stream = TcpStream::connect("127.0.0.1:8080").unwrap();
stream.write_all(b"ping").await.unwrap();
let mut buf = [0u8; 4];
let _ = stream.read(&mut buf).await.unwrap();
});