| 1 | //! A global executor built on top of async-executor and async_io |
| 2 | //! |
| 3 | //! The global executor is lazily spawned on first use. It spawns as many threads |
| 4 | //! as the number of cpus by default. You can override this using the |
| 5 | //! `ASYNC_GLOBAL_EXECUTOR_THREADS` environment variable. |
| 6 | //! |
| 7 | //! # Examples |
| 8 | //! |
| 9 | //! ``` |
| 10 | //! # use futures_lite::future; |
| 11 | //! |
| 12 | //! // spawn a task on the multi-threaded executor |
| 13 | //! let task1 = async_global_executor::spawn(async { |
| 14 | //! 1 + 2 |
| 15 | //! }); |
| 16 | //! // spawn a task on the local executor (same thread) |
| 17 | //! let task2 = async_global_executor::spawn_local(async { |
| 18 | //! 3 + 4 |
| 19 | //! }); |
| 20 | //! let task = future::zip(task1, task2); |
| 21 | //! |
| 22 | //! // run the executor |
| 23 | //! async_global_executor::block_on(async { |
| 24 | //! assert_eq!(task.await, (3, 7)); |
| 25 | //! }); |
| 26 | //! ``` |
| 27 | |
| 28 | #![forbid (unsafe_code)] |
| 29 | #![warn (missing_docs, missing_debug_implementations, rust_2018_idioms)] |
| 30 | |
| 31 | #[cfg (doctest)] |
| 32 | doc_comment::doctest!("../README.md" ); |
| 33 | |
| 34 | pub use async_executor::Task; |
| 35 | pub use config::GlobalExecutorConfig; |
| 36 | pub use executor::{block_on, spawn, spawn_blocking, spawn_local}; |
| 37 | pub use init::{init, init_with_config}; |
| 38 | pub use threading::{spawn_more_threads, stop_current_thread, stop_thread}; |
| 39 | |
| 40 | mod config; |
| 41 | mod executor; |
| 42 | mod init; |
| 43 | mod reactor; |
| 44 | mod threading; |
| 45 | |
| 46 | #[cfg (feature = "tokio" )] |
| 47 | mod tokio; |
| 48 | #[cfg (feature = "tokio02" )] |
| 49 | mod tokio02; |
| 50 | #[cfg (feature = "tokio03" )] |
| 51 | mod tokio03; |
| 52 | |