Repository: actix/actix-net (language: rust)

Issue:
The Tokio runtime is not customizable for workers
## Expected Behavior
Using [`actix_rt::System::run_in_tokio`] I can run Actix with a custom Tokio runtime. Specifically, I want to use the [`tokio-compat`] runtime so I can support legacy Tokio 0.1 code.

## Current Behavior
Using [`actix_rt::System::run_in_tokio`] only runs the main "thread" or future under the custom runtime. Workers still use the default runtime ([link to relevant code](https://github.com/actix/actix-net/blob/f6c697a2dd706d8d981f439c9b77e60b982c16cd/actix-rt/src/arbiter.rs#L115)).

## Possible Solution
Provide a way to pass a runtime or runtime factory to Actix for its use.

## Steps to Reproduce (for bugs)
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
<!--- reproduce this bug. Include code to reproduce, if relevant -->
1. Clone and run https://github.com/Mcat12/actix-compat-runtime-crash
2. See that the spawned Tokio 0.1 and 0.2 futures ran (they print a message)
3. Go to http://127.0.0.1:8000/
4. See that the worker has panicked with "called `Result::unwrap()` on an `Err` value: SpawnError { is_shutdown: true }"

## Context
I need to use a crate which uses Tokio 0.1 (and futures 0.1). This crate sometimes spawns new futures (Hyper 0.12 client). This fails because there is no Tokio 0.1 executor.

Previous related issues:
- https://github.com/actix/actix-web/issues/913
- https://github.com/actix/actix-web/issues/1186

## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->

* Rust Version (I.e, output of `rustc -V`): 1.44.1
* Actix Web Version: 2.0.0

[`actix_rt::System::run_in_tokio`]: https://docs.rs/actix-rt/1.1.1/actix_rt/struct.System.html#method.run_in_tokio
[`tokio-compat`]: https://docs.rs/tokio-compat/0.1.6/tokio_compat


Discussion / hints:
`actix-rt` lives in another repository isn't it?
https://github.com/actix/actix-net
If someone has the permissions necessary to transfer this issue to that repo, that would be appreciated. Otherwise I can copy it over manually.
@Mcat12 Running into exact same issue ... any updates? I've tried so many different options and cannot find a solution.
@swstack the Tokio 0.1 code was a bit old and needed refactoring, so we rewrote it in Tokio 0.2 and async/await.

If that's not a possibility for you, I'd suggest forking actix to make it use a different runtime.
I guess I may have encountered a similar problem, but it was in `tokio 1.x` . Can someone help me check https://github.com/ritedb/riteraft/issues/1

Fix patch:
diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md
index e42be17b9f..abfb6c95d4 100644
--- a/actix-rt/CHANGES.md
+++ b/actix-rt/CHANGES.md
@@ -1,6 +1,9 @@
 # Changes
 
 ## Unreleased - 2021-xx-xx
+- Expose `System::with_tokio_rt` and `Arbiter::with_tokio_rt`. [#430]
+
+[#430]: https://github.com/actix/actix-net/pull/430
 
 
 ## 2.5.0 - 2021-11-22
diff --git a/actix-rt/src/arbiter.rs b/actix-rt/src/arbiter.rs
index 43b1bdc361..95256360c3 100644
--- a/actix-rt/src/arbiter.rs
+++ b/actix-rt/src/arbiter.rs
@@ -108,7 +108,6 @@ impl Arbiter {
     ///
     /// [tokio-runtime]: tokio::runtime::Runtime
     #[cfg(not(all(target_os = "linux", feature = "io-uring")))]
-    #[doc(hidden)]
     pub fn with_tokio_rt<F>(runtime_factory: F) -> Arbiter
     where
         F: Fn() -> tokio::runtime::Runtime + Send + 'static,
diff --git a/actix-rt/src/system.rs b/actix-rt/src/system.rs
index 635f3c187e..0ea3547da3 100644
--- a/actix-rt/src/system.rs
+++ b/actix-rt/src/system.rs
@@ -46,7 +46,6 @@ impl System {
     /// Create a new System using the [Tokio Runtime](tokio-runtime) returned from a closure.
     ///
     /// [tokio-runtime]: tokio::runtime::Runtime
-    #[doc(hidden)]
     pub fn with_tokio_rt<F>(runtime_factory: F) -> SystemRunner
     where
         F: Fn() -> tokio::runtime::Runtime,


Test patch: