mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 10:14:35 +00:00
refactor: remove ScopedTask (#2125)
* replace ScopedTask with AbortOnDropHandle
This commit is contained in:
@@ -6,10 +6,10 @@ use axum::{
|
||||
routing,
|
||||
};
|
||||
use axum_embed::ServeEmbed;
|
||||
use easytier::common::scoped_task::ScopedTask;
|
||||
use rust_embed::RustEmbed;
|
||||
use std::net::SocketAddr;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio_util::task::AbortOnDropHandle;
|
||||
|
||||
/// Embed assets for web dashboard, build frontend first
|
||||
#[derive(RustEmbed, Clone)]
|
||||
@@ -59,7 +59,7 @@ pub fn build_router(api_host: Option<url::Url>) -> Router {
|
||||
pub struct WebServer {
|
||||
bind_addr: SocketAddr,
|
||||
router: Router,
|
||||
serve_task: Option<ScopedTask<()>>,
|
||||
serve_task: Option<AbortOnDropHandle<()>>,
|
||||
}
|
||||
|
||||
impl WebServer {
|
||||
@@ -71,14 +71,13 @@ impl WebServer {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn start(self) -> Result<ScopedTask<()>, anyhow::Error> {
|
||||
pub async fn start(self) -> Result<AbortOnDropHandle<()>, anyhow::Error> {
|
||||
let listener = TcpListener::bind(self.bind_addr).await?;
|
||||
let app = self.router;
|
||||
|
||||
let task = tokio::spawn(async move {
|
||||
let task = AbortOnDropHandle::new(tokio::spawn(async move {
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
})
|
||||
.into();
|
||||
}));
|
||||
|
||||
Ok(task)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user