mirror of https://github.com/fafhrd91/actix-net
Refine runtime match
This commit is contained in:
parent
d428ac275e
commit
297b172644
|
@ -272,11 +272,6 @@ impl ServerWorker {
|
||||||
thread::Builder::new()
|
thread::Builder::new()
|
||||||
.name(format!("actix-server-worker-{}", idx))
|
.name(format!("actix-server-worker-{}", idx))
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
// Conditionally setup actix system.
|
|
||||||
if let Some(system) = system {
|
|
||||||
System::set_current(system);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare service construct future.
|
// Prepare service construct future.
|
||||||
let fut = async {
|
let fut = async {
|
||||||
let mut services = Vec::new();
|
let mut services = Vec::new();
|
||||||
|
@ -301,8 +296,8 @@ impl ServerWorker {
|
||||||
// All future runs in a LocalSet for being able to run !Send future.
|
// All future runs in a LocalSet for being able to run !Send future.
|
||||||
let local = tokio::task::LocalSet::new();
|
let local = tokio::task::LocalSet::new();
|
||||||
|
|
||||||
match rt_handle {
|
match (rt_handle, system) {
|
||||||
Ok(handle) => {
|
(Ok(handle), None) => {
|
||||||
// Use existing tokio runtime with handle.
|
// Use existing tokio runtime with handle.
|
||||||
let res = handle.block_on(local.run_until(fut));
|
let res = handle.block_on(local.run_until(fut));
|
||||||
|
|
||||||
|
@ -330,7 +325,12 @@ impl ServerWorker {
|
||||||
Err(e) => f(Some(e)),
|
Err(e) => f(Some(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
(_, system) => {
|
||||||
|
// Conditionally setup actix system.
|
||||||
|
if let Some(system) = system {
|
||||||
|
System::set_current(system);
|
||||||
|
}
|
||||||
|
|
||||||
// No existing tokio runtime found. Start new runtime.
|
// No existing tokio runtime found. Start new runtime.
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
|
|
Loading…
Reference in New Issue