Skip to content

Commit

Permalink
0.47.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Mar 24, 2024
1 parent 9633d73 commit 6f1fb78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "0.46.0")
.package(url: "https://github.com/dankinsoid/swift-api-client.git", from: "0.47.0")
],
targets: [
.target(
Expand Down
24 changes: 14 additions & 10 deletions Sources/SwiftAPIClient/Modifiers/BackgroundModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,23 @@ private struct RetryOnEnterForegroundMiddleware: HTTPClientMiddleware {
configs: APIClient.Configs,
next: (URLRequest, APIClient.Configs) async throws -> (T, HTTPURLResponse)
) async throws -> (T, HTTPURLResponse) {
let wasInBackground = WasInBackgroundService()
let isInBackground = await UIApplication.shared.applicationState == .background
if !isInBackground {
await wasInBackground.start()
}
do {
return try await next(request, configs)
} catch {
if await wasInBackground.wasInBackground {
func makeRequest() async throws -> (T, HTTPURLResponse) {
let wasInBackground = WasInBackgroundService()
var isInBackground = await UIApplication.shared.applicationState == .background
if !isInBackground {
await wasInBackground.start()
}
do {
return try await next(request, configs)
} catch {
isInBackground = await UIApplication.shared.applicationState == .background
if !isInBackground, await wasInBackground.wasInBackground {
return try await makeRequest()
}
throw error
}
throw error
}
return try await makeRequest()
}
}

Expand Down

0 comments on commit 6f1fb78

Please sign in to comment.