Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #382 from admin-ch/bugfix/fixes-race-condition
Browse files Browse the repository at this point in the history
Fixes race condition
  • Loading branch information
stmitt authored Oct 13, 2022
2 parents 5b49da8 + 4cde148 commit 474adb0
Showing 1 changed file with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,27 @@ class HomescreenCertificatesViewController: ViewController {
}

private func startChecks() {
DispatchQueue.global(qos: .userInitiated).async {
for i in self.certificateViews {
if let lightQrCode = i.certificate?.lightCertificate?.certificate {
VerifierManager.shared.addObserver(self, for: lightQrCode, modes: Verifier.currentModes()) { [weak i] state in
i?.verificationState = state
}
} else if let qrCode = i.certificate?.qrCode {
VerifierManager.shared.addObserver(self, for: qrCode, modes: Verifier.currentModes()) { [weak i] state in
i?.verificationState = state
}
} else if let transferCode = i.certificate?.transferCode,
transferCode.state != .failed // only start when not already failed
{
TransferManager.shared.addObserver(self, for: transferCode.transferCode) { [weak i] result in
guard let strongI = i else { return }
switch result {
case .success:
// TransferManager adds all the certificates
strongI.transferError = nil
case let .failure(error):
strongI.transferError = error
}
let modes = Verifier.currentModes()
for i in certificateViews {
if let lightQrCode = i.certificate?.lightCertificate?.certificate {
VerifierManager.shared.addObserver(self, for: lightQrCode, modes: modes) { [weak i] state in
i?.verificationState = state
}
} else if let qrCode = i.certificate?.qrCode {
VerifierManager.shared.addObserver(self, for: qrCode, modes: modes) { [weak i] state in
i?.verificationState = state
}
} else if let transferCode = i.certificate?.transferCode,
transferCode.state != .failed // only start when not already failed
{
TransferManager.shared.addObserver(self, for: transferCode.transferCode) { [weak i] result in
guard let strongI = i else { return }
switch result {
case .success:
// TransferManager adds all the certificates
strongI.transferError = nil
case let .failure(error):
strongI.transferError = error
}
}
}
Expand Down

0 comments on commit 474adb0

Please sign in to comment.