Files
Kymo/kymo/Core/Monitors/DiskHealthMonitor.swift
T

20 lines
723 B
Swift

import Foundation
/// SMART belongs to the physical storage backing the home volume, not each APFS volume.
actor DiskHealthMonitor {
private var cached: DiskHealthMetrics?
private var nextRead: TimeInterval = 0
private var pending: Task<DiskHealthMetrics?, Never>?
func sample() async -> DiskHealthMetrics? {
if let pending { return await pending.value }
guard ProcessInfo.processInfo.systemUptime >= nextRead else { return cached }
let task = Task { await SMARTServiceClient.read() }
pending = task
cached = await task.value
pending = nil
nextRead = ProcessInfo.processInfo.systemUptime + (cached == nil ? 600 : 3600)
return cached
}
}