async_global_executor/lib.rs
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)]
32doc_comment::doctest!("../README.md");
33
34pub use async_executor::Task;
35pub use config::GlobalExecutorConfig;
36pub use executor::{block_on, spawn, spawn_blocking, spawn_local};
37pub use init::{init, init_with_config};
38pub use threading::{spawn_more_threads, stop_current_thread, stop_thread};
39
40mod config;
41mod executor;
42mod init;
43mod reactor;
44mod threading;
45
46#[cfg(feature = "tokio")]
47mod tokio;