Crate async_rs

Source
Expand description

A collection of traits and implementations to define a common interface across async runtimes

§Features

  • tokio: enable the tokio implementation (default)
  • smol: enable the smol implementation
  • async-global-executor: enable the async-global-executor implementation
  • async-io: enable the async-io reactor implementation

§Example

use async_rs::{Executor, Reactor, Runtime, TokioRuntime}; use std::{io, sync::Arc, time::Duration};

async fn get_a(rt: Arc) -> io::Result { rt.clone() .spawn_blocking(move || rt.block_on(async { Ok(12) })) .await }

async fn get_b(rt: Arc) -> io::Result { rt.spawn(async { Ok(30) }).await }

async fn tokio_main() -> io::Result<()> { let rt = Arc::new(Runtime::tokio()); let a = get_a(rt.clone()).await?; let b = get_b(rt.clone()).await?; rt.sleep(Duration::from_millis(500)).await; assert_eq!(a + b, 42); Ok(()) }

#[tokio::main] async fn main() -> io::Result<()> { tokio_main().await }

#[tokio::test] async fn tokio() -> io::Result<()> { tokio_main().await }

Structs§

AsyncGlobalExecutor
Dummy object implementing executor-trait common interfaces on top of async-global-executor
AsyncIO
Dummy object implementing reactor common interfaces on top of async-io
IOHandle
A synchronous IO handle
Runtime
A full-featured Runtime implementation
RuntimeParts
Wrapper around separate Executor and Reactor implementing RuntimeKit
Smol
Dummy object implementing async common interfaces on top of smol
Tokio
Dummy object implementing async common interfaces on top of tokio

Traits§

AsyncIOHandle
A trait representing an asynchronous IO handle
AsyncToSocketAddrs
A common interface for resolving domain name + port to SocketAddr
Executor
A common interface for spawning futures on top of an executor
Reactor
A common interface for performing actions on a reactor
RuntimeKit
Supertrait to tag a type that implements all required components for a Runtime
Task
A common interface to wait for a Task completion, let it run n the background or cancel it.

Type Aliases§

AGERuntime
Type alias for the async-global-executor runtime
SmolRuntime
Type alias for the smol runtime
TokioRuntime
Type alias for the tokio runtime