15 lines
517 B
Swift
15 lines
517 B
Swift
import Foundation
|
|
|
|
/// Missing capabilities back off independently; success in another zone cannot reset this state.
|
|
nonisolated struct SensorSchedule {
|
|
private(set) var deadline: TimeInterval = 0
|
|
private var failures = 0
|
|
|
|
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))))
|
|
}
|
|
}
|