Fix: [CP-XX] TransactionObserver can be started infinite times

Refs: https://gitlab.protontech.ch/apple/shared/protoncore/-/merge_requests/2041
This commit is contained in:
Tiziano Bruni 2025-01-17 11:07:19 +00:00
commit ed01c8e501

View file

@ -138,20 +138,24 @@ public final class TransactionsObserver: TransactionsObserverProviding, @uncheck
// MARK: Public methods
public func start() async throws {
if !isON {
try initRequiredComponents()
try initRequiredComponents()
guard let planComposer = planComposer, let _ = transactionHandler else {
assertionFailure("TransactionsObserver: TransactionsObserverConfiguration required to start the observer")
throw TransactionsObserverError.requiredSubComponentInitFailed
}
guard let planComposer = planComposer, let _ = transactionHandler else {
assertionFailure("TransactionsObserver: TransactionsObserverConfiguration required to start the observer")
throw TransactionsObserverError.requiredSubComponentInitFailed
if !planComposer.hasData {
_ = try await planComposer.fetchAvailablePlans()
}
updates?.cancel()
updates = newTransactionListenerTask()
isON = true
debugPrint("TransactionsObserver started: \(isON)")
} else {
debugPrint("TransactionsObserver already running, nothing to start")
}
if !planComposer.hasData {
_ = try await planComposer.fetchAvailablePlans()
}
updates = newTransactionListenerTask()
isON = true
debugPrint("TransactionsObserver started: \(isON)")
}
public func stop() {