mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 04:47:39 +03:00
Force runtime selection (#435)
This commit is contained in:
parent
b0a7658bf1
commit
5a907c8ed8
5 changed files with 41 additions and 95 deletions
|
@ -1,6 +1,10 @@
|
|||
# Changes
|
||||
|
||||
## [0.4.18] - 2024-09-xx
|
||||
## [0.4.19] - 2024-10-11
|
||||
|
||||
* Force runtime feature selection
|
||||
|
||||
## [0.4.18] - 2024-09-24
|
||||
|
||||
* Update to glommio v0.9
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-rt"
|
||||
version = "0.4.18"
|
||||
version = "0.4.19"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
description = "ntex runtime"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
|
@ -9,7 +9,9 @@ repository = "https://github.com/ntex-rs/ntex.git"
|
|||
documentation = "https://docs.rs/ntex-rt/"
|
||||
categories = ["network-programming", "asynchronous"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
build = "build.rs"
|
||||
edition = "2021"
|
||||
rust-version = "1.75"
|
||||
|
||||
[lib]
|
||||
name = "ntex_rt"
|
||||
|
|
24
ntex-rt/build.rs
Normal file
24
ntex-rt/build.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use std::{collections::HashSet, env};
|
||||
|
||||
fn main() {
|
||||
let mut features = HashSet::<&'static str>::default();
|
||||
|
||||
for (key, _val) in env::vars() {
|
||||
let _ = match key.as_ref() {
|
||||
"CARGO_FEATURE_COMPIO" => features.insert("compio"),
|
||||
"CARGO_FEATURE_TOKIO" => features.insert("tokio"),
|
||||
"CARGO_FEATURE_GLOMMIO" => features.insert("glommio"),
|
||||
"CARGO_FEATURE_ASYNC_STD" => features.insert("async-std"),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
if features.is_empty() {
|
||||
panic!("Runtime must be selected '--feature=ntex\\$runtime', available options are \"compio\", \"tokio\", \"async-std\", \"glommio\"");
|
||||
} else if features.len() > 1 {
|
||||
panic!(
|
||||
"Only one runtime feature could be selected, current selection {:?}",
|
||||
features
|
||||
);
|
||||
}
|
||||
}
|
|
@ -132,7 +132,10 @@ mod compio {
|
|||
/// Runs the provided future, blocking the current thread until the future
|
||||
/// completes.
|
||||
pub fn block_on<F: Future<Output = ()>>(fut: F) {
|
||||
log::debug!("Create compio runtime and block on future");
|
||||
log::info!(
|
||||
"Starting compio runtime, driver {:?}",
|
||||
comp_io::driver::DriverType::current()
|
||||
);
|
||||
let rt = Runtime::new().unwrap();
|
||||
rt.block_on(fut);
|
||||
}
|
||||
|
@ -461,99 +464,11 @@ mod glommio {
|
|||
#[cfg(feature = "tokio")]
|
||||
pub use self::tokio::*;
|
||||
|
||||
#[cfg(all(
|
||||
not(feature = "tokio"),
|
||||
not(feature = "compio"),
|
||||
not(feature = "glommio"),
|
||||
feature = "async-std",
|
||||
))]
|
||||
#[cfg(feature = "async-std")]
|
||||
pub use self::asyncstd::*;
|
||||
|
||||
#[cfg(all(
|
||||
not(feature = "tokio"),
|
||||
not(feature = "compio"),
|
||||
not(feature = "async-std"),
|
||||
feature = "glommio"
|
||||
))]
|
||||
#[cfg(feature = "glommio")]
|
||||
pub use self::glommio::*;
|
||||
|
||||
#[cfg(all(
|
||||
not(feature = "tokio"),
|
||||
not(feature = "glommio"),
|
||||
not(feature = "async-std"),
|
||||
feature = "compio"
|
||||
))]
|
||||
#[cfg(feature = "compio")]
|
||||
pub use self::compio::*;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(all(
|
||||
not(feature = "tokio"),
|
||||
not(feature = "async-std"),
|
||||
not(feature = "compio"),
|
||||
not(feature = "glommio")
|
||||
))]
|
||||
mod no_rt {
|
||||
use std::task::{Context, Poll};
|
||||
use std::{fmt, future::Future, marker::PhantomData, pin::Pin};
|
||||
|
||||
/// Runs the provided future, blocking the current thread until the future
|
||||
/// completes.
|
||||
pub fn block_on<F: Future<Output = ()>>(_: F) {
|
||||
panic!("async runtime is not configured");
|
||||
}
|
||||
|
||||
pub fn spawn<F>(_: F) -> JoinHandle<F::Output>
|
||||
where
|
||||
F: Future + 'static,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn spawn_blocking<F, T>(_: F) -> JoinHandle<T>
|
||||
where
|
||||
F: FnOnce() -> T + Send + Sync + 'static,
|
||||
T: Send + 'static,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Blocking operation completion future. It resolves with results
|
||||
/// of blocking function execution.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub struct JoinHandle<T> {
|
||||
t: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> JoinHandle<T> {
|
||||
pub fn is_finished(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Future for JoinHandle<T> {
|
||||
type Output = Result<T, JoinError>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct JoinError;
|
||||
|
||||
impl fmt::Display for JoinError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "JoinError")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for JoinError {}
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
not(feature = "tokio"),
|
||||
not(feature = "async-std"),
|
||||
not(feature = "compio"),
|
||||
not(feature = "glommio")
|
||||
))]
|
||||
pub use self::no_rt::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue