perf(efficiency): 接入真实CPU能量并隔离展示与采样需求
This commit is contained in:
@@ -4,11 +4,17 @@ import Foundation
|
||||
nonisolated struct SensorSchedule {
|
||||
private(set) var deadline: TimeInterval = 0
|
||||
private var failures = 0
|
||||
private let successInterval: TimeInterval
|
||||
private let failureInterval: TimeInterval
|
||||
init(successInterval: TimeInterval = 10, failureInterval: TimeInterval = 60) {
|
||||
self.successInterval = successInterval
|
||||
self.failureInterval = failureInterval
|
||||
}
|
||||
|
||||
func isDue(at now: TimeInterval) -> Bool { now >= deadline }
|
||||
|
||||
mutating func complete(available: Bool, at now: TimeInterval) {
|
||||
failures = available ? 0 : min(failures + 1, 5)
|
||||
deadline = now + (available ? 10 : min(600, 60 * pow(2, Double(failures - 1))))
|
||||
mutating func complete(available: Bool, at now: TimeInterval, retryInterval: TimeInterval? = nil) {
|
||||
failures = available ? 0 : min(failures + 1, 8)
|
||||
deadline = now + (retryInterval ?? (available ? successInterval : min(600, failureInterval * pow(2, Double(failures - 1)))))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user