-
Notifications
You must be signed in to change notification settings - Fork 176
Create background Hub clients only if necessary #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ public struct HubApi: Sendable { | |
| private let backgroundUncachedClient: HubClient | ||
| #endif | ||
|
|
||
| private let networkMonitor = NetworkMonitor() | ||
| private let networkMonitor = NetworkMonitor.shared | ||
| public typealias RepoType = Hub.RepoType | ||
| public typealias Repo = Hub.Repo | ||
|
|
||
|
|
@@ -188,20 +188,19 @@ public struct HubApi: Sendable { | |
| useBackgroundSession: false | ||
| ) | ||
| #if !canImport(FoundationNetworking) | ||
| self.backgroundCachedClient = Self.buildHubClient( | ||
| self.backgroundCachedClient = useBackgroundSession ? Self.buildHubClient( | ||
| host: hostURL, | ||
| tokenProvider: tokenProvider, | ||
| cache: cache, | ||
| useBackgroundSession: true | ||
| ) | ||
| self.backgroundUncachedClient = Self.buildHubClient( | ||
| ) : self.foregroundCachedClient | ||
| self.backgroundUncachedClient = useBackgroundSession ? Self.buildHubClient( | ||
| host: hostURL, | ||
| tokenProvider: tokenProvider, | ||
| cache: nil, | ||
| useBackgroundSession: true | ||
| ) | ||
| ) : self.foregroundUncachedClient | ||
| #endif | ||
| NetworkMonitor.shared.startMonitoring() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not need to manually call
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like the correct fix — especially if we're keeping |
||
| } | ||
|
|
||
| /// The shared Hub API instance with default configuration. | ||
|
|
@@ -1144,7 +1143,7 @@ extension HubApi { | |
|
|
||
| static let shared = NetworkMonitor() | ||
|
|
||
| init() { | ||
| private init() { | ||
| #if canImport(Network) | ||
| monitor = NWPathMonitor() | ||
| queue = DispatchQueue(label: "HubApi.NetworkMonitor") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.