Repository: bevyengine/bevy
File: crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs (Rust)

Code before:
                waker: Arc::default(),
            }
        }
    }

    impl Future for DiagnosticTask {
        type Output = ();

        fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
            self.waker.register(cx.waker());

            if self.last_refresh.elapsed() > sysinfo::MINIMUM_CPU_UPDATE_INTERVAL {
                self.last_refresh = Instant::now();

                let sysinfo_refresh_data = SysinfoRefreshData::new(&mut self.system);
                self.sender.send(sysinfo_refresh_data).unwrap();
            }

            Poll::Pending
        }
    }

    fn wake_diagnostic_task(task: ResMut<SysinfoTask>) {
        if let Some(waker) = task.waker.take() {
            waker.wake();
        }
    }

    fn read_diagnostic_task(mut diagnostics: Diagnostics, mut task: ResMut<SysinfoTask>) {
        while let Ok(data) = task.receiver.get().try_recv() {
            diagnostics.add_measurement(
                &SystemInformationDiagnosticsPlugin::SYSTEM_CPU_USAGE,
                || data.system_cpu_usage,
            );
            diagnostics.add_measurement(
                &SystemInformationDiagnosticsPlugin::SYSTEM_MEM_USAGE,
                || data.system_mem_usage,
            );
            diagnostics.add_measurement(
                &SystemInformationDiagnosticsPlugin::PROCESS_CPU_USAGE,
                || data.process_cpu_usage,
            );
            diagnostics.add_measurement(
                &SystemInformationDiagnosticsPlugin::PROCESS_MEM_USAGE,
                || data.process_mem_usage,
            );
        }
    }

    impl Default for SystemInfo {
        fn default() -> Self {

Review comment (suggestion):
```suggestion
        task.waker.wake();
```

Alternatively just replace calls to this function with just a call to AtomicWaker::wake

Code after:
        fn new(sender: Sender<SysinfoRefreshData>) -> Self {
            Self {
                system: System::new_with_specifics(
                    RefreshKind::nothing()
                        .with_cpu(CpuRefreshKind::nothing().with_cpu_usage())
                        .with_memory(MemoryRefreshKind::everything()),
                ),
                // Avoids initial delay on first refresh
                last_refresh: Instant::now() - sysinfo::MINIMUM_CPU_UPDATE_INTERVAL,
                sender,
                waker: Arc::default(),
            }
        }
    }

    impl Future for DiagnosticTask {
        type Output = ();

        fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
            self.waker.register(cx.waker());

            if self.last_refresh.elapsed() > sysinfo::MINIMUM_CPU_UPDATE_INTERVAL {
                self.last_refresh = Instant::now();

                let sysinfo_refresh_data = SysinfoRefreshData::new(&mut self.system);
                self.sender.send(sysinfo_refresh_data).unwrap();
            }

            // Always reschedules
            Poll::Pending
        }
    }

    fn wake_diagnostic_task(task: ResMut<SysinfoTask>) {
        task.waker.wake();
    }

    fn read_diagnostic_task(mut diagnostics: Diagnostics, mut task: ResMut<SysinfoTask>) {
        while let Ok(data) = task.receiver.get().try_recv() {
            diagnostics.add_measurement(
                &SystemInformationDiagnosticsPlugin::SYSTEM_CPU_USAGE,
                || data.system_cpu_usage,
            );
            diagnostics.add_measurement(
                &SystemInformationDiagnosticsPlugin::SYSTEM_MEM_USAGE,
                || data.system_mem_usage,
            );
            diagnostics.add_measurement(
                &SystemInformationDiagnosticsPlugin::PROCESS_CPU_USAGE,
                || data.process_cpu_usage,
            );