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

Make PollingDefaults threadsafe #1122

Merged
merged 2 commits into from
Feb 26, 2024
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
33 changes: 30 additions & 3 deletions Sources/Nimble/Polling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,36 @@ public struct AsyncDefaults {
/// or slow down poll interval. Default timeout interval is 1, and poll interval is 0.01.
///
/// - Note: This used to be known as ``AsyncDefaults``.
public struct PollingDefaults {
public static var timeout: NimbleTimeInterval = .seconds(1)
public static var pollInterval: NimbleTimeInterval = .milliseconds(10)
public struct PollingDefaults: @unchecked Sendable {
private static let lock = NSRecursiveLock()

private static var _timeout: NimbleTimeInterval = .seconds(1)
private static var _pollInterval: NimbleTimeInterval = .milliseconds(10)

public static var timeout: NimbleTimeInterval {
get {
lock.lock()
defer { lock.unlock() }
return _timeout
}
set {
lock.lock()
defer { lock.unlock() }
_timeout = newValue
}
}
public static var pollInterval: NimbleTimeInterval {
get {
lock.lock()
defer { lock.unlock() }
return _pollInterval
}
set {
lock.lock()
defer { lock.unlock() }
_pollInterval = newValue
}
}
}

internal enum AsyncMatchStyle {
Expand Down
Loading