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
//! Dynamic task executor.
//!
//! Inspired by golang runtime.
//!
//! It is okay to do blocking inside a task, the executor will
//! detect this, and scale the thread pool.
//!
//! But, please keep note that every time you do blocking, it will
//! create thread via [`thread::spawn`], and the number of thread you can create
//! is not unlimited, so the number of blocking task you can [`spawn`] is also not unlimited
//!
//! [`thread::spawn`]: https://doc.rust-lang.org/std/thread/fn.spawn.html
//! [`spawn`]: fn.spawn.html
//!
//! # Example
//!
//! ```rust,ignore
//! use std::thread;
//! use std::time::Duration;
//!
//! use futures_timer::Delay;
//!
//! lelet::spawn(async {
//!     for _ in 0..10 {
//!         Delay::new(Duration::from_secs(1)).await;
//!         println!("Non-blocking Hello World");
//!     }
//! });
//!
//! lelet::spawn(async {
//!     for _ in 0..10 {
//!         thread::sleep(Duration::from_secs(1));
//!         println!("Blocking Hello World");
//!     }
//! });
//!
//! thread::sleep(Duration::from_secs(11));
//! ```

#[doc(hidden)]
pub mod thread_pool;

mod executor;
pub use executor::spawn;
pub use executor::JoinHandle;

#[doc(hidden)]
pub use executor::get_num_cpus;
#[doc(hidden)]
pub use executor::set_num_cpus;

#[doc(hidden)]
pub use executor::detach_current_thread;