1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! 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-async `mio` types (`TcpStream`, `UdpSocket`,
//! event listener, timeouts). Enabled by the `net` feature.
//! - [`common`] – utilities such as [`common::ready_future::ReadyFuture`] and
//! [`common::ready_observable::ReadyObservable`] for composing async workflows.
//!
//! # Quick start
//!
//! Basic timer usage:
//!
//! ```no_run
//! 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:
//!
//! ```no_run
//! 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();
//! });
//! ```