File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,7 +56,22 @@ class ScheduleManager: ObservableObject {
5656 }
5757
5858 private func startTimer( ) {
59- timer = Timer . scheduledTimer ( withTimeInterval: 30 , repeats: true ) { [ weak self] _ in
59+ // fire at XX:01 of every minute — schedules always start/end on minute boundaries
60+ // so this gives ~1s response time with only 1 poll per minute
61+ let now = Date ( )
62+ let cal = Calendar . current
63+ let nextMinute = cal. nextDate ( after: now, matching: DateComponents ( second: 1 ) , matchingPolicy: . nextTime) !
64+ let delay = nextMinute. timeIntervalSince ( now)
65+
66+ let oneShot = Timer . scheduledTimer ( withTimeInterval: delay, repeats: false ) { [ weak self] _ in
67+ self ? . evaluate ( )
68+ self ? . startRepeatingTimer ( )
69+ }
70+ RunLoop . main. add ( oneShot, forMode: . common)
71+ }
72+
73+ private func startRepeatingTimer( ) {
74+ timer = Timer . scheduledTimer ( withTimeInterval: 60 , repeats: true ) { [ weak self] _ in
6075 self ? . evaluate ( )
6176 }
6277 RunLoop . main. add ( timer!, forMode: . common)
You can’t perform that action at this time.
0 commit comments