Crate async_foundation

Crate async_foundation 

Source
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

§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();
});

Modules§

common
Common async utilities used across the crate.
net
Async networking primitives built on top of non-async mio.
timer
Timer primitives for async code.