Skip to content

Commit da13a33

Browse files
committed
fix sleep behavior
1 parent 20b4354 commit da13a33

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Sources/Daycal/CalendarStore.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ final class CalendarStore: ObservableObject {
3939
await refreshEvents()
4040
scheduleAutoRefresh()
4141
} catch {
42+
if isCancellationError(error) {
43+
return
44+
}
4245
if isOfflineError(error) {
4346
if tokenStore.hasToken {
4447
authState = .offline
@@ -69,6 +72,9 @@ final class CalendarStore: ObservableObject {
6972
scheduleAutoRefresh()
7073
} catch {
7174
if Task.isCancelled { return }
75+
if isCancellationError(error) {
76+
return
77+
}
7278
if isOfflineError(error) {
7379
authState = tokenStore.hasToken ? .offline : .signedOut
7480
return
@@ -110,6 +116,9 @@ final class CalendarStore: ObservableObject {
110116
authState = .signedIn
111117
}
112118
} catch {
119+
if isCancellationError(error) {
120+
return
121+
}
113122
if let authError = error as? CalendarAuthError, authError == .missingToken {
114123
authState = .signedOut
115124
return
@@ -173,6 +182,16 @@ final class CalendarStore: ObservableObject {
173182
return false
174183
}
175184
}
185+
186+
private func isCancellationError(_ error: Error) -> Bool {
187+
if error is CancellationError {
188+
return true
189+
}
190+
if let urlError = error as? URLError, urlError.code == .cancelled {
191+
return true
192+
}
193+
return false
194+
}
176195
}
177196

178197
extension CalendarStore: @unchecked Sendable {}

0 commit comments

Comments
 (0)