summaryrefslogtreecommitdiffstats
path: root/futures/src/executor.rs
blob: 144a41f8a4eaac9b67497087797150a6be5a1522 (plain) (blame)
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
//! Choose your preferred executor to power a runtime.
mod null;

#[cfg(feature = "thread-pool")]
mod thread_pool;

#[cfg(feature = "thread-pool")]
pub use thread_pool::ThreadPool;

#[cfg(feature = "tokio")]
mod tokio;

#[cfg(feature = "async-std")]
mod async_std;

pub use null::Null;

#[cfg(feature = "tokio")]
pub use self::tokio::Tokio;

#[cfg(feature = "async-std")]
pub use self::async_std::AsyncStd;

use futures::Future;

pub trait Executor: Sized {
    fn new() -> Result<Self, futures::io::Error>
    where
        Self: Sized;

    fn spawn(&self, future: impl Future<Output = ()> + Send + 'static);

    fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
        f()
    }
}