Skip to content

Commit

Permalink
Fix error message in NotificationListener and refactor observation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kasianov-mikhail committed Dec 14, 2024
1 parent 0985b86 commit a3ff3c6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions Sources/Scout/Core/NotificationListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public actor NotificationListener {
var errorDescription: String? {
switch self {
case .alreadySetup:
return "ActivityListener is already setup"
return "NotificationListener is already setup"
}
}
}
Expand All @@ -67,21 +67,19 @@ public actor NotificationListener {
}

isSetup = true

observeTable()
table.observe()
}
}

// MARK: - Observe

extension NotificationListener.ActionTable {

/// Adds observers for each notification in the action table.
private func observeTable() {
for (name, action) in table {
/// Observes the notifications in the action table and performs the associated actions.
fileprivate func observe() {
for (name, action) in self {
NotificationCenter.default.addObserver(forName: name, object: nil, queue: nil) { _ in
Task {
do {
try await action()
} catch {
print(error.localizedDescription)
}
}
Task(operation: action)
}
}
}
Expand Down

0 comments on commit a3ff3c6

Please sign in to comment.