Skip to content

Commit c82c366

Browse files
committed
Cancel the DiagnosticTask when SysinfoTask drops
1 parent c09c0be commit c82c366

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ mod internal {
8888
use bevy_ecs::resource::Resource;
8989
use bevy_ecs::{prelude::ResMut, system::Commands};
9090
use bevy_platform::{cell::SyncCell, time::Instant};
91-
use bevy_tasks::AsyncComputeTaskPool;
91+
use bevy_tasks::{AsyncComputeTaskPool, Task};
9292
use log::info;
9393
use sysinfo::{CpuRefreshKind, MemoryRefreshKind, RefreshKind, System};
9494

@@ -108,8 +108,9 @@ mod internal {
108108
let (tx, rx) = mpsc::channel();
109109
let diagnostic_task = DiagnosticTask::new(tx);
110110
let waker = Arc::clone(&diagnostic_task.waker);
111-
AsyncComputeTaskPool::get().spawn(diagnostic_task).detach();
111+
let task = AsyncComputeTaskPool::get().spawn(diagnostic_task);
112112
commands.insert_resource(SysinfoTask {
113+
_task: task,
113114
receiver: SyncCell::new(rx),
114115
waker,
115116
});
@@ -170,6 +171,7 @@ mod internal {
170171

171172
#[derive(Resource)]
172173
struct SysinfoTask {
174+
_task: Task<()>,
173175
receiver: SyncCell<Receiver<SysinfoRefreshData>>,
174176
waker: Arc<AtomicWaker>,
175177
}

0 commit comments

Comments
 (0)