Skip to content

Commit 9338367

Browse files
committed
fix: locks
1 parent 3a65339 commit 9338367

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

Sources/UnleashProxyClientSwift/Metrics/Metrics.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ public class Metrics {
104104
}
105105

106106
func sendMetrics() {
107+
let localBucket: Bucket
108+
let clockFunction: () -> Date
109+
107110
lock.lock()
108111
bucket.closeBucket()
109-
let localBucket = bucket
110-
let clockFunction = self.clock
112+
localBucket = bucket
113+
clockFunction = self.clock
111114
bucket = Bucket(clock: clockFunction)
112115
lock.unlock()
113116

@@ -133,12 +136,18 @@ public class Metrics {
133136
}
134137

135138
func createRequest(payload: Data) -> URLRequest {
139+
let urlValue: URL
140+
let clientKeyValue: String
141+
let appNameValue: String
142+
let connectionIdValue: UUID
143+
let customHeadersValue: [String: String]
144+
136145
lock.lock()
137-
let urlValue = self.url
138-
let clientKeyValue = self.clientKey
139-
let appNameValue = self.appName
140-
let connectionIdValue = self.connectionId
141-
let customHeadersValue = self.customHeaders
146+
urlValue = self.url
147+
clientKeyValue = self.clientKey
148+
appNameValue = self.appName
149+
connectionIdValue = self.connectionId
150+
customHeadersValue = self.customHeaders
142151
lock.unlock()
143152

144153
var request = URLRequest(url: urlValue.appendingPathComponent("client/metrics"))

Sources/UnleashProxyClientSwift/Poller/Poller.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,18 @@ public class Poller {
140140
request.httpMethod = "GET"
141141
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
142142

143+
let apiKeyValue: String
144+
let currentEtag: String
145+
let appNameValue: String
146+
let connectionIdValue: UUID
147+
let customHeadersValue: [String: String]
148+
143149
lock.lock()
144-
let apiKeyValue = self.apiKey
145-
let currentEtag = self.etag
146-
let appNameValue = self.appName
147-
let connectionIdValue = self.connectionId
148-
let customHeadersValue = self.customHeaders
150+
apiKeyValue = self.apiKey
151+
currentEtag = self.etag
152+
appNameValue = self.appName
153+
connectionIdValue = self.connectionId
154+
customHeadersValue = self.customHeaders
149155
lock.unlock()
150156

151157
request.setValue(apiKeyValue, forHTTPHeaderField: "Authorization")

0 commit comments

Comments
 (0)