Skip to content

Commit 7dc904f

Browse files
committed
use explicit lock/unlock for 5.10 compatibility
1 parent 36254b4 commit 7dc904f

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

Sources/SwiftkubeClient/Config/KubernetesClientConfig.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ public final class CachedFileTokenSource: @unchecked Sendable {
8181

8282
/// The path to the token file on disk.
8383
public var path: String {
84-
lock.withLock { state.path }
84+
lock.lock()
85+
defer { lock.unlock() }
86+
return state.path
8587
}
8688

8789
private struct State {
@@ -104,21 +106,22 @@ public final class CachedFileTokenSource: @unchecked Sendable {
104106

105107
/// Returns the current token, re-reading from disk if the cache has expired.
106108
public func token() -> String? {
107-
lock.withLock {
108-
let now = NIODeadline.now()
109-
if let cachedToken = state.cachedToken, now < state.expiry {
110-
return cachedToken
111-
}
109+
lock.lock()
110+
defer { lock.unlock() }
112111

113-
guard let newToken = try? String(contentsOfFile: state.path, encoding: .utf8) else {
114-
return nil
115-
}
112+
let now = NIODeadline.now()
113+
if let cachedToken = state.cachedToken, now < state.expiry {
114+
return cachedToken
115+
}
116116

117-
let trimmed = newToken.trimmingCharacters(in: .whitespacesAndNewlines)
118-
state.cachedToken = trimmed
119-
state.expiry = now + state.cacheDuration
120-
return trimmed
117+
guard let newToken = try? String(contentsOfFile: state.path, encoding: .utf8) else {
118+
return nil
121119
}
120+
121+
let trimmed = newToken.trimmingCharacters(in: .whitespacesAndNewlines)
122+
state.cachedToken = trimmed
123+
state.expiry = now + state.cacheDuration
124+
return trimmed
122125
}
123126
}
124127

0 commit comments

Comments
 (0)