File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1919- tokio: enable the tokio implementation * (default)*
2020- smol: enable the smol implementation
2121- async-global-executor: enable the async-global-executor implementation
22+ - async-io: enable the async-io reactor implementation
2223
2324## Example
2425
26+ ``` rust
27+ use async_rs :: {Executor , Reactor , Runtime , TokioRuntime };
28+ use std :: {io, sync :: Arc , time :: Duration };
29+
30+ async fn get_a (rt : Arc <TokioRuntime >) -> io :: Result <u32 > {
31+ rt . clone ()
32+ . spawn_blocking (move || rt . block_on (async { Ok (12 ) }))
33+ . await
34+ }
35+
36+ async fn get_b (rt : Arc <TokioRuntime >) -> io :: Result <u32 > {
37+ rt . spawn (async { Ok (30 ) }). await
38+ }
39+
40+ async fn tokio_main () -> io :: Result <()> {
41+ let rt = Arc :: new (Runtime :: tokio ());
42+ let a = get_a (rt . clone ()). await ? ;
43+ let b = get_b (rt . clone ()). await ? ;
44+ rt . sleep (Duration :: from_millis (500 )). await ;
45+ assert_eq! (a + b , 42 );
46+ Ok (())
47+ }
48+
49+ #[tokio:: main]
50+ async fn main () -> io :: Result <()> {
51+ tokio_main (). await
52+ }
53+
54+ #[tokio:: test]
55+ async fn tokio () -> io :: Result <()> {
56+ tokio_main (). await
57+ }
58+ ```
Original file line number Diff line number Diff line change 11#![ deny( missing_docs, missing_debug_implementations, unsafe_code) ]
22
33//! 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+ //! }
445
546mod runtime;
647pub use runtime:: * ;
You can’t perform that action at this time.
0 commit comments