Skip to main content

ntex_rt/
lib.rs

1//! A runtime implementation that runs everything on the current thread.
2#![deny(clippy::pedantic)]
3#![allow(
4    clippy::missing_fields_in_debug,
5    clippy::must_use_candidate,
6    clippy::missing_errors_doc
7)]
8
9mod arbiter;
10mod builder;
11mod driver;
12mod handle;
13mod pool;
14pub mod signals;
15mod system;
16mod task;
17
18mod rt;
19pub mod rt_default;
20
21#[cfg(feature = "compio")]
22pub mod rt_compio;
23#[cfg(feature = "tokio")]
24pub mod rt_tokio;
25
26pub use self::arbiter::{Arbiter, get_item, remove_all_items, set_item, with_item};
27pub use self::builder::{Builder, SystemRunner};
28pub use self::driver::{BlockFuture, Driver, DriverType, Notify, PollResult, Runner};
29pub use self::pool::{BlockingError, BlockingResult, ThreadPool};
30pub use self::rt::{Runtime, RuntimeBuilder};
31pub use self::system::{Id, PingRecord, System};
32pub use self::task::{task_callbacks, task_opt_callbacks};
33
34/// Spawns a blocking task in a new thread, and wait for it.
35///
36/// The task will not be cancelled even if the future is dropped.
37pub fn spawn_blocking<F, R>(f: F) -> BlockingResult<R>
38where
39    F: FnOnce() -> R + Send + 'static,
40    R: Send + 'static,
41{
42    if let Some(sys) = System::try_current() {
43        sys.spawn_blocking(f)
44    } else {
45        ThreadPool::execute_inplace(f)
46    }
47}
48
49#[cfg(feature = "tokio")]
50pub use self::rt_tokio::*;
51
52#[cfg(all(feature = "compio", not(feature = "tokio")))]
53pub use self::rt_compio::*;
54
55#[cfg(all(not(feature = "tokio"), not(feature = "compio")))]
56pub use self::rt_default::*;
57
58pub(crate) type HashMap<K, V> =
59    std::collections::HashMap<K, V, foldhash::fast::RandomState>;
60pub(crate) type HashSet<V> = std::collections::HashSet<V, foldhash::fast::RandomState>;