async_rs/
lib.rs

1#![deny(missing_docs, missing_debug_implementations, unsafe_code)]
2
3//! A collection of traits and implementations to define a common interface across async runtimes
4//!
5//! ## Features
6//!
7//! - tokio: enable the tokio implementation *(default)*
8//! - smol: enable the smol implementation
9//! - async-global-executor: enable the async-global-executor implementation
10//! - async-io: enable the async-io reactor implementation
11//!
12//! ## Example
13//!
14//!use async_rs::{Executor, Reactor, Runtime, TokioRuntime};
15//! use std::{io, sync::Arc, time::Duration};
16//!
17//! async fn get_a(rt: Arc<TokioRuntime>) -> io::Result<u32> {
18//!     rt.clone()
19//!         .spawn_blocking(move || rt.block_on(async { Ok(12) }))
20//!         .await
21//! }
22//!
23//! async fn get_b(rt: Arc<TokioRuntime>) -> io::Result<u32> {
24//!     rt.spawn(async { Ok(30) }).await
25//! }
26//!
27//! async fn tokio_main() -> io::Result<()> {
28//!     let rt = Arc::new(Runtime::tokio());
29//!     let a = get_a(rt.clone()).await?;
30//!     let b = get_b(rt.clone()).await?;
31//!     rt.sleep(Duration::from_millis(500)).await;
32//!     assert_eq!(a + b, 42);
33//!     Ok(())
34//! }
35//!
36//! #[tokio::main]
37//! async fn main() -> io::Result<()> {
38//!     tokio_main().await
39//! }
40//!
41//! #[tokio::test]
42//! async fn tokio() -> io::Result<()> {
43//!     tokio_main().await
44//! }
45
46mod runtime;
47pub use runtime::*;
48
49mod traits;
50pub use traits::*;
51
52mod implementors;
53pub use implementors::*;