Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes an issue with multiple timers being scheduled #529

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@

class MessageQueueManager {
var interval: Double = 600
private var queueTimer: Timer!
private var queueTimer: Timer?
// The local message store is used to keep messages that can't be displayed because the route rule doesnt match.
private var localMessageStore: [String: Message] = [:]

func setup(skipQueueCheck: Bool = false) {
if let queueTimer {
queueTimer.invalidate()
self.queueTimer = nil

Check warning on line 13 in Sources/MessagingInApp/Gist/Managers/MessageQueueManager.swift

View check run for this annotation

Codecov / codecov/patch

Sources/MessagingInApp/Gist/Managers/MessageQueueManager.swift#L12-L13

Added lines #L12 - L13 were not covered by tests
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add this to deinit of this class?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let queueTimer {
queueTimer.invalidate()
self.queueTimer = nil
}
self.queueTimer?.invalidate()
self.queueTimer = nil

Nit-picky suggestion. I think this code reads easier without the if because we are re-constructing the queueTimer in the line below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the instance is created and maintained from a static class, I don't think its required.


queueTimer = Timer.scheduledTimer(
timeInterval: interval,
target: self,
Expand Down