Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit dd54032

Browse files
committed
Add event mapping to HistoryCoordinator
1 parent afdab42 commit dd54032

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Sources/History/HistoryCoordinator.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,20 @@ public protocol HistoryCoordinating: AnyObject {
4848

4949
/// Coordinates access to History. Uses its own queue with high qos for all operations.
5050
final public class HistoryCoordinator: HistoryCoordinating {
51+
52+
public enum Event {
5153

54+
case dataCleaningFailed(_ error: Error)
55+
case dataCleaningFinished
56+
57+
}
58+
59+
let eventMapper: EventMapping<Event>
5260
let historyStoringProvider: () -> HistoryStoring
5361

54-
public init(historyStoring: @autoclosure @escaping () -> HistoryStoring) {
62+
public init(historyStoring: @autoclosure @escaping () -> HistoryStoring, eventMapper: EventMapping<Event>) {
5563
self.historyStoringProvider = historyStoring
64+
self.eventMapper = eventMapper
5665
}
5766

5867
public func loadHistory(onCleanFinished: @escaping () -> Void) {
@@ -203,13 +212,15 @@ final public class HistoryCoordinator: HistoryCoordinating {
203212
private func clean(until date: Date, onCleanFinished: (() -> Void)? = nil) {
204213
historyStoring.cleanOld(until: date)
205214
.receive(on: DispatchQueue.main)
206-
.sink(receiveCompletion: { completion in
215+
.sink(receiveCompletion: { [weak self] completion in
207216
switch completion {
208217
case .finished:
218+
self?.eventMapper.fire(.dataCleaningFinished)
209219
Logger.history.debug("History cleaned successfully")
210220
case .failure(let error):
211221
// This should really be a pixel
212222
Logger.history.error("Cleaning of history failed: \(error.localizedDescription)")
223+
self?.eventMapper.fire(.dataCleaningFailed(error))
213224
}
214225
onCleanFinished?()
215226
}, receiveValue: { [weak self] history in

0 commit comments

Comments
 (0)