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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! A Rust async runtime abstraction library.
//!
//! Provides a unified [`Runtime`] enum and a set of [`traits`]
//! (`Executor`, `Reactor`, `Dns`, …) that abstract over Tokio, smol, and
//! async-global-executor. Applications select exactly one runtime via feature
//! flags; library crates depend on the trait objects and remain
//! runtime-agnostic.
//!
//! # Feature flags
//!
//! | Flag | Notes |
//! |------|-------|
//! | `tokio` *(default)* | Tokio runtime |
//! | `smol` | smol executor |
//! | `async-global-executor` | async-global-executor |
//! | `async-io` | async-io reactor (required by `smol`) |
//! | `hickory-dns` | Hickory DNS resolver (tokio only) |
//!
//! # Example
//!
//! ```rust
//! # #[cfg(feature="tokio")]
//! # {
//! use async_rs::{Runtime, TokioRuntime, traits::*};
//! use std::{io, time::Duration};
//!
//! async fn get_a(rt: &TokioRuntime) -> io::Result<u32> {
//! rt.spawn_blocking(|| Ok(12)).await
//! }
//!
//! async fn get_b(rt: &TokioRuntime) -> io::Result<u32> {
//! rt.spawn(async { Ok(30) }).await
//! }
//!
//! async fn tokio_main(rt: &TokioRuntime) -> io::Result<()> {
//! let a = get_a(rt).await?;
//! let b = get_b(rt).await?;
//! rt.sleep(Duration::from_millis(500)).await;
//! assert_eq!(a + b, 42);
//! Ok(())
//! }
//!
//! fn main() -> io::Result<()> {
//! let rt = Runtime::tokio()?;
//! rt.block_on(tokio_main(&rt))
//! }
//! # }
//! ```
pub use *;
pub use *;