Skip to content

Commit

Permalink
Notify immediately on timer start + stop the timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Guretzki committed Sep 5, 2024
1 parent f12d52f commit 8c8af40
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions AdyenActions/Components/QRCode/ExpirationTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ internal final class ExpirationTimer {
timer = Timer.scheduledTimer(withTimeInterval: tickInterval, repeats: true) { [weak self] _ in
self?.onTimerTick()
}

// Notify immediately
notify()
}

internal func stopTimer() {
Expand All @@ -52,8 +55,16 @@ internal final class ExpirationTimer {
}

private func onTimerTick() {
defer { notify() }

timeLeft -= 1

if timeLeft <= 0 {
stopTimer()
}
}

private func notify() {
if timeLeft > 0 {
onTick(timeLeft)
} else {
Expand Down

0 comments on commit 8c8af40

Please sign in to comment.