Skip to content

Commit

Permalink
fix: Remove async lets
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrizio Demaria <[email protected]>
  • Loading branch information
fabriziodemaria committed Jan 15, 2024
1 parent 223418c commit 0536a63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Sources/ConfidenceProvider/Apply/FlagApplierWithRetries.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ final class FlagApplierWithRetries: FlagApplier {

public func apply(flagName: String, resolveToken: String) async {
let applyTime = Date.backport.now
async let (data, added) = await cacheDataInteractor.add(
let (data, added) = await cacheDataInteractor.add(
resolveToken: resolveToken,
flagName: flagName,
applyTime: applyTime
)
guard await added == true else {
guard added == true else {
// If record is found in the cache, early return (de-duplication).
// Triggerring batch apply in case if there are any unsent events stored
await triggerBatch()
return
}

await self.writeToFile(data: data)
self.writeToFile(data: data)
await triggerBatch()
}

// MARK: private

private func triggerBatch() async {
async let cacheData = await cacheDataInteractor.cache
let cacheData = await cacheDataInteractor.cache
await cacheData.resolveEvents.asyncForEach { resolveEvent in
let appliesToSend = resolveEvent.events.filter { $0.status == .created }
.chunk(size: 20)
Expand Down
9 changes: 2 additions & 7 deletions Sources/ConfidenceProvider/Http/NetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ final class NetworkClient: HttpClient {
let retryWait: TimeInterval? = retryHandler.retryIn()

do {
async let (data, response) = await self.session.data(for: request)
guard let httpResponse = try? await response as? HTTPURLResponse else {
let (data, response) = try await self.session.data(for: request)
guard let httpResponse = response as? HTTPURLResponse else {
await completion(nil, nil, HttpClientError.invalidResponse)
return
}
Expand All @@ -87,11 +87,6 @@ final class NetworkClient: HttpClient {
await self.perform(request: request, retry: retry, completion: completion)
return
}
guard let data = try? await data else {
let error = ConfidenceError.internalError(message: "Unable to complete request")
await completion(httpResponse, nil, error)
return
}
await completion(httpResponse, data, nil)
} catch {
if self.shouldRetry(error: error), let retryWait {
Expand Down

0 comments on commit 0536a63

Please sign in to comment.