Suggestion: make actix async-runtime-agnostic
uniconductive opened this issue · 2 comments
Now tokio runtime is owned by actix_rt internals and it is tokio only.
In actix_rt::System:
fn with_tokio_rt<F>(runtime_factory: F) -> SystemRunner
where
F: Fn() -> tokio::runtime::Runtime
What if there will be something like this instead of with_tokio_rt?
trait AsyncRuntime {
fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
where
F: std::future::Future + Send + 'static,
F::Output: Send + 'static;
fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static;
fn block_on<F: std::future::Future>(&self, future: F) -> F::Output;
}
fn with_any_rt(runtime: impl AsyncRuntime) -> SystemRunner
{
....
}
Goal: to have runtime-agnostic actix, without owning of async runtime.
Being runtime agnostic is currently not a goal of the Actix Web project and probably wont be until std
has some sort of Executor trait.
Goal: to have runtime-agnostic actix, without owning of async runtime.
It's not that simple as you think it is. web applications need more than async exectuor to make everything work. You need to generic over io driver and timer driver too.
And tbh there is no real runtime-agnostic web application now in Rust due to the point robjtede pointed out. There is no unified traits for all the necessary async operations needed and it leads to messy feature flaged "runtime-agnostic" apps with locked in public traits from futures
or tokio
.
It also worth to mention that tokio
imo is the best runtime for actix-web. (I had multiple forks that making actix-web run on async-std
/smol
/glommio
). From my observation tokio
have the best performance/consistency, the best async web ecosystem in Rust.