mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-30 15:59:21 +00:00
refactor: remove ScopedTask (#2125)
* replace ScopedTask with AbortOnDropHandle
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use dashmap::DashMap;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::{collections::BTreeMap, path::PathBuf, sync::Arc};
|
||||
use tokio_util::task::AbortOnDropHandle;
|
||||
|
||||
use crate::{
|
||||
common::{
|
||||
config::{ConfigFileControl, ConfigLoader, ConfigSource, TomlConfigLoader},
|
||||
global_ctx::{EventBusSubscriber, GlobalCtxEvent},
|
||||
log,
|
||||
scoped_task::ScopedTask,
|
||||
},
|
||||
launcher::{NetworkInstance, NetworkInstanceRunningInfo},
|
||||
proto::{self},
|
||||
@@ -27,7 +27,7 @@ impl Drop for DaemonGuard {
|
||||
|
||||
pub struct NetworkInstanceManager {
|
||||
instance_map: Arc<DashMap<uuid::Uuid, NetworkInstance>>,
|
||||
instance_stop_tasks: Arc<DashMap<uuid::Uuid, ScopedTask<()>>>,
|
||||
instance_stop_tasks: Arc<DashMap<uuid::Uuid, AbortOnDropHandle<()>>>,
|
||||
stop_check_notifier: Arc<tokio::sync::Notify>,
|
||||
instance_error_messages: Arc<DashMap<uuid::Uuid, String>>,
|
||||
config_dir: Option<PathBuf>,
|
||||
@@ -78,12 +78,12 @@ impl NetworkInstanceManager {
|
||||
let stop_check_notifier = self.stop_check_notifier.clone();
|
||||
self.instance_stop_tasks.insert(
|
||||
instance_id,
|
||||
ScopedTask::from(tokio::spawn(async move {
|
||||
AbortOnDropHandle::new(tokio::spawn(async move {
|
||||
let Some(instance_stop_notifier) = instance_stop_notifier else {
|
||||
return;
|
||||
};
|
||||
let _t = instance_event_receiver
|
||||
.map(|event| ScopedTask::from(handle_event(instance_id, event)));
|
||||
.map(|event| AbortOnDropHandle::new(handle_event(instance_id, event)));
|
||||
instance_stop_notifier.notified().await;
|
||||
if let Some(instance) = instance_map.get(&instance_id)
|
||||
&& let Some(error) = instance.get_latest_error_msg()
|
||||
|
||||
Reference in New Issue
Block a user