Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions Sources/NautilusTelemetry/Utilities/FlushTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright © 2025 Airbnb Inc. All rights reserved.

import Foundation
import os

// MARK: - FlushTimer

Expand Down Expand Up @@ -42,10 +43,12 @@ class FlushTimer {
}

func suspend() {
if !suspended {
// Must match calls between suspend/resume
flushTimer.suspend()
suspended = true
lock.withLock {
if !suspended {
// Must match calls between suspend/resume
flushTimer.suspend()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we need to lock in deinit to protect the flush timer, or are we only trying to protect the suspension state?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's just the suspension state.

suspended = true
}
}
}

Expand All @@ -59,16 +62,18 @@ class FlushTimer {
leeway: DispatchTimeInterval.milliseconds(100)
)
flushTimer.activate()
if suspended {
flushTimer.resume()
suspended = false
lock.withLock {
if suspended {
flushTimer.resume()
suspended = false
}
}
}

// MARK: Private

private var _flushInterval: TimeInterval

private var lock = OSAllocatedUnfairLock()
}

extension DispatchTimeInterval {
Expand Down