fix silly async bugs
This commit is contained in:
parent
6e57913905
commit
19b31626c9
@ -9,7 +9,7 @@ use std::{
|
||||
use async_trait::async_trait;
|
||||
use threadpool::ThreadPool;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::runtime::Handle;
|
||||
use tokio_io_timeout::TimeoutStream;
|
||||
|
||||
use crate::pin_handler;
|
||||
@ -55,7 +55,7 @@ where
|
||||
let listener = TcpListener::bind(host).await?;
|
||||
let old_handler = handler;
|
||||
let handler = Arc::new(move |now_server, sock| {
|
||||
Runtime::new().unwrap().block_on(old_handler(now_server, sock));
|
||||
Handle::current().block_on(old_handler(now_server, sock));
|
||||
});
|
||||
|
||||
let host_clone = String::from(host).clone();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use tokio::{runtime::Runtime, task::JoinHandle};
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use super::{
|
||||
start_server_new_thread,
|
||||
@ -142,7 +142,7 @@ impl<T: HttpServer + Send + 'static + Sync> HttpServerStarter<T> {
|
||||
let running_clone = running.clone();
|
||||
|
||||
let thread = if self.threads == 0 {
|
||||
Runtime::new().unwrap().spawn(async move {
|
||||
tokio::spawn(async move {
|
||||
start_server_new_thread(
|
||||
self.http_server,
|
||||
&self.host,
|
||||
@ -153,7 +153,7 @@ impl<T: HttpServer + Send + 'static + Sync> HttpServerStarter<T> {
|
||||
.expect("http server error");
|
||||
})
|
||||
} else if self.threads == 1 {
|
||||
Runtime::new().unwrap().spawn(async move {
|
||||
tokio::spawn(async move {
|
||||
start_server_sync(
|
||||
self.http_server,
|
||||
&self.host,
|
||||
@ -164,7 +164,7 @@ impl<T: HttpServer + Send + 'static + Sync> HttpServerStarter<T> {
|
||||
.expect("http server error");
|
||||
})
|
||||
} else {
|
||||
Runtime::new().unwrap().spawn(async move {
|
||||
tokio::spawn(async move {
|
||||
start_server_with_threadpool(
|
||||
self.http_server,
|
||||
&self.host,
|
||||
|
Loading…
x
Reference in New Issue
Block a user