Skip to content

Commit

Permalink
Remove observer for current notification on errors (#1500)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyh committed May 28, 2023
1 parent ae835c4 commit e56ac85
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Amethyst/Model/ApplicationObservation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,18 @@ struct ApplicationObservation<Delegate: ApplicationObservationDelegate> {

return Observable.from(notifications)
.scan([]) { observed, notification -> [Notification] in
let notifications = observed + [notification]

do {
try self.addObserver(for: notification)
} catch {
log.error("Failed to add observer \(notification) on application \(self.application.title() ?? "<unknown>") (\(self.application.pid())): \(error)")
self.removeObservers(notifications: observed)
let applicationTitle = self.application.title() ?? "<unknown>"
log.error("Failed to add observer \(notification) on application \(applicationTitle) (\(self.application.pid())): \(error)")
self.removeObservers(notifications: notifications)
throw error
}

return observed + [notification]
return notifications
}
.map { _ in }
}
Expand Down

0 comments on commit e56ac85

Please sign in to comment.