runtime.spawn

This commit is contained in:
MeexReay 2024-09-08 01:20:01 +03:00
parent 958f71dd95
commit 9aec967306
2 changed files with 7 additions and 6 deletions

View File

@ -10,6 +10,7 @@ use std::{
use tokio::io::AsyncReadExt;
use rusty_pool::ThreadPool;
use tokio::net::{TcpListener, TcpStream};
use tokio::runtime::Runtime;
use tokio_io_timeout::TimeoutStream;
pub mod error;
@ -104,7 +105,7 @@ where
let now_server = Arc::clone(&server);
threadpool.spawn((&handler)(now_server, sock));
threadpool.spawn_await((&handler)(now_server, sock));
}
threadpool.join();
@ -140,7 +141,7 @@ where
let now_server = Arc::clone(&server);
tokio::spawn((&handler)(now_server, sock));
Runtime::new().unwrap().spawn((&handler)(now_server, sock));
}
server.on_close().await;

View File

@ -1,4 +1,4 @@
use tokio::task::JoinHandle;
use tokio::{runtime::Runtime, task::JoinHandle};
use super::{
handler_connection, start_server_new_thread, start_server_sync, start_server_with_threadpool, Handler, HttpServer
@ -138,7 +138,7 @@ impl<T: HttpServer + Send + 'static + Sync> HttpServerStarter<T> {
let running_clone = running.clone();
let thread = if self.threads == 0 {
tokio::spawn(async move {
Runtime::new().unwrap().spawn(async move {
start_server_new_thread(
self.http_server,
&self.host,
@ -149,7 +149,7 @@ impl<T: HttpServer + Send + 'static + Sync> HttpServerStarter<T> {
.expect("http server error");
})
} else if self.threads == 1 {
tokio::spawn(async move {
Runtime::new().unwrap().spawn(async move {
start_server_sync(
self.http_server,
&self.host,
@ -160,7 +160,7 @@ impl<T: HttpServer + Send + 'static + Sync> HttpServerStarter<T> {
.expect("http server error");
})
} else {
tokio::spawn(async move {
Runtime::new().unwrap().spawn(async move {
start_server_with_threadpool(
self.http_server,
&self.host,