Skip to content

Commit 5ec0d3a

Browse files
authored
Make PollingDefaults threadsafe (#1078)
1 parent 9cf3e53 commit 5ec0d3a

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

Sources/Nimble/Polling.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,36 @@ public struct AsyncDefaults {
3434
/// or slow down poll interval. Default timeout interval is 1, and poll interval is 0.01.
3535
///
3636
/// - Note: This used to be known as ``AsyncDefaults``.
37-
public struct PollingDefaults {
38-
public static var timeout: NimbleTimeInterval = .seconds(1)
39-
public static var pollInterval: NimbleTimeInterval = .milliseconds(10)
37+
public struct PollingDefaults: @unchecked Sendable {
38+
private static let lock = NSRecursiveLock()
39+
40+
private static var _timeout: NimbleTimeInterval = .seconds(1)
41+
private static var _pollInterval: NimbleTimeInterval = .milliseconds(10)
42+
43+
public static var timeout: NimbleTimeInterval {
44+
get {
45+
lock.lock()
46+
defer { lock.unlock() }
47+
return _timeout
48+
}
49+
set {
50+
lock.lock()
51+
defer { lock.unlock() }
52+
_timeout = newValue
53+
}
54+
}
55+
public static var pollInterval: NimbleTimeInterval {
56+
get {
57+
lock.lock()
58+
defer { lock.unlock() }
59+
return _pollInterval
60+
}
61+
set {
62+
lock.lock()
63+
defer { lock.unlock() }
64+
_pollInterval = newValue
65+
}
66+
}
4067
}
4168

4269
internal enum AsyncMatchStyle {

0 commit comments

Comments
 (0)