Docs.rs
  • async-io-2.0.0
    • async-io 2.0.0
    • Docs.rs crate page
    • Apache-2.0 OR MIT
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • github:smol-rs:admins
    • Dependencies
      • async-lock ^2.6 normal
      • cfg-if ^1 normal
      • concurrent-queue ^2.2.0 normal
      • futures-io ^0.3.28 normal
      • futures-lite ^1.11.0 normal
      • parking ^2.0.0 normal
      • polling ^3.0.0 normal
      • rustix ^0.38.2 normal
      • slab ^0.4.2 normal
      • tracing ^0.1.37 normal
      • waker-fn ^1.1.0 normal
      • async-channel ^1 dev
      • async-net ^1 dev
      • blocking ^1 dev
      • criterion ^0.4 dev
      • getrandom ^0.2.7 dev
      • signal-hook ^0.3 dev
      • tempfile ^3 dev
      • inotify ^0.10.1 dev
      • timerfd ^1 dev
      • windows-sys ^0.48.0 normal
      • uds_windows ^1 dev
    • Versions
    • 100% of the crate is documented
  • Go to latest version
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate async_io

logo

async_io2.0.0

  • All Items
  • Modules
  • Structs
  • Traits
  • Functions

Crates

  • async_io
?
Change settings

Crate async_io

source ·
Expand description

Async I/O and timers.

This crate provides two tools:

  • Async, an adapter for standard networking types (and many other types) to use in async programs.
  • Timer, a future or stream that emits timed events.

For concrete async networking types built on top of this crate, see async-net.

Implementation

The first time Async or Timer is used, a thread named “async-io” will be spawned. The purpose of this thread is to wait for I/O events reported by the operating system, and then wake appropriate futures blocked on I/O or timers when they can be resumed.

To wait for the next I/O event, the “async-io” thread uses epoll on Linux/Android/illumos, kqueue on macOS/iOS/BSD, event ports on illumos/Solaris, and IOCP on Windows. That functionality is provided by the polling crate.

However, note that you can also process I/O events and wake futures on any thread using the block_on() function. The “async-io” thread is therefore just a fallback mechanism processing I/O events in case no other threads are.

Examples

Connect to example.com:80, or time out after 10 seconds.

use async_io::{Async, Timer};
use futures_lite::{future::FutureExt, io};

use std::net::{TcpStream, ToSocketAddrs};
use std::time::Duration;

let addr = "example.com:80".to_socket_addrs()?.next().unwrap();

let stream = Async::<TcpStream>::connect(addr).or(async {
    Timer::after(Duration::from_secs(10)).await;
    Err(io::ErrorKind::TimedOut.into())
})
.await?;

Modules

  • os
    Platform-specific functionality.

Structs

  • Async
    Async adapter for I/O types.
  • Readable
    Future for Async::readable.
  • ReadableOwned
    Future for Async::readable_owned.
  • Timer
    A future or stream that emits timed events.
  • Writable
    Future for Async::writable.
  • WritableOwned
    Future for Async::writable_owned.

Traits

  • IoSafe
    Types whose I/O trait implementations do not drop the underlying I/O source.

Functions

  • block_on
    Blocks the current thread on a future, processing I/O events when idle.

Results

Query parser error: "Unexpected - (did you mean ->?)".