diff --git a/ylong_http_client/src/lib.rs b/ylong_http_client/src/lib.rs index f1431e45ae0c544f2e9491bad5edcb05ea5e70a8..a4e29524a4473edf310afe9739077dc14d3a79b3 100644 --- a/ylong_http_client/src/lib.rs +++ b/ylong_http_client/src/lib.rs @@ -115,4 +115,16 @@ pub(crate) mod runtime { #[cfg(all(feature = "ylong_base", feature = "http2"))] pub(crate) use crate::{split, Reader as ReadHalf, Writer as WriteHalf}; + + #[cfg(any(feature = "http2", feature = "http3"))] + use std::future::Future; + + #[cfg(any(feature = "http2", feature = "http3"))] + pub(crate) fn runtime_spawn(fut: T) -> JoinHandle<()> + where + T: Future, + T: Send + Sync + 'static, + { + crate::runtime::spawn(Box::into_pin(Box::new(fut) as Box + Send + Sync>)) + } } diff --git a/ylong_http_client/src/util/dispatcher.rs b/ylong_http_client/src/util/dispatcher.rs index 4e8f5dc0d8cbfa8a2ac2efb57bdc187ce3558a5c..611b526931094b98a11c8b6a6b29088724217688 100644 --- a/ylong_http_client/src/util/dispatcher.rs +++ b/ylong_http_client/src/util/dispatcher.rs @@ -503,7 +503,7 @@ pub(crate) mod http2 { let (read, write) = crate::runtime::split(io); let settings_sync = Arc::new(Mutex::new(SettingsSync::default())); let send_settings_sync = settings_sync.clone(); - let send = crate::runtime::spawn(async move { + let send = crate::runtime::runtime_spawn(async move { let mut writer = write; if async_send_preface(&mut writer).await.is_ok() { let encoder = FrameEncoder::new(DEFAULT_MAX_FRAME_SIZE, use_huffman); @@ -515,14 +515,14 @@ pub(crate) mod http2 { handles.push(send); let recv_settings_sync = settings_sync.clone(); - let recv = crate::runtime::spawn(async move { + let recv = crate::runtime::runtime_spawn(async move { let decoder = FrameDecoder::new(); let mut recv = RecvData::new(decoder, recv_settings_sync, read, resp_tx); let _ = Pin::new(&mut recv).await; }); handles.push(recv); - let manager = crate::runtime::spawn(async move { + let manager = crate::runtime::runtime_spawn(async move { let mut conn_manager = ConnManager::new(settings_sync, input_channel.0, resp_rx, req_rx, controller); let _ = Pin::new(&mut conn_manager).await; @@ -938,7 +938,7 @@ pub(crate) mod http3 { io_shutdown.clone(), io_goaway.clone(), ); - let stream_handle = crate::runtime::spawn(async move { + let stream_handle = crate::runtime::runtime_spawn(async move { if stream_manager.init(config).is_err() { return; } @@ -946,7 +946,7 @@ pub(crate) mod http3 { }); handles.push(stream_handle); - let io_handle = crate::runtime::spawn(async move { + let io_handle = crate::runtime::runtime_spawn(async move { let mut io_manager = IOManager::new(io, conn, io_manager_rx, stream_manager_tx); let _ = Pin::new(&mut io_manager).await; });