@@ -103,8 +103,9 @@ extension SupportManager {
103
103
// MARK: Version checking
104
104
extension SupportManager {
105
105
func performCheck( ) {
106
- checkVersion { [ weak self] versionUpdate in
107
- self ? . notify ( versionUpdate)
106
+ Task { @MainActor in
107
+ let versionUpdate = await checkVersion ( )
108
+ self . notify ( versionUpdate)
108
109
}
109
110
}
110
111
@@ -114,37 +115,41 @@ extension SupportManager {
114
115
}
115
116
}
116
117
117
- func checkVersion( completion: @escaping ( VersionUpdate ) -> Void ) {
118
- let group = DispatchGroup ( )
119
- var results = [ String : Result < VersionUpdate ? , Error > ] ( )
120
- supports. value. values. forEach { support in
121
- group. enter ( )
122
- support. checkVersion ( bundleIdentifier: Bundle . main. bundleIdentifier!, currentVersion: Bundle . main. shortVersionString) { result in
123
- results [ support. identifier] = result
124
- group. leave ( )
118
+ func checkVersion( ) async -> VersionUpdate {
119
+
120
+ let results = await withTaskGroup ( of: ( VersionUpdate? , String) . self) { group in
121
+ var updatesFromServices = [ ( VersionUpdate? , String) ] ( )
122
+
123
+ supports. value. values. forEach { support in
124
+ group. addTask {
125
+ return ( await support. checkVersion ( bundleIdentifier: Bundle . main. bundleIdentifier!, currentVersion: Bundle . main. shortVersionString) , support. identifier)
126
+ }
125
127
}
128
+
129
+ for await update in group {
130
+ updatesFromServices. append ( update)
131
+ }
132
+
133
+ return updatesFromServices
126
134
}
127
- group. notify ( queue: DispatchQueue . main) { [ weak self] in
128
- guard let self = self else { return }
129
- self . saveState ( )
130
- let ( identifierWithHighestVersionUpdate, aggregatedVersionUpdate) = self . aggregate ( results: results)
131
- self . identifierWithHighestVersionUpdate = identifierWithHighestVersionUpdate
132
- completion ( aggregatedVersionUpdate)
133
- }
135
+
136
+ self . saveState ( )
137
+ let ( identifierWithHighestVersionUpdate, aggregatedVersionUpdate) = self . aggregate ( results: results)
138
+ self . identifierWithHighestVersionUpdate = identifierWithHighestVersionUpdate
139
+ return aggregatedVersionUpdate
134
140
}
135
141
136
- private func aggregate( results: [ String : Result < VersionUpdate ? , Error > ] ) -> ( String ? , VersionUpdate ) {
142
+ private func aggregate( results: [ ( VersionUpdate ? , String ) ] ) -> ( String ? , VersionUpdate ) {
137
143
var aggregatedVersionUpdate = VersionUpdate . default
138
144
var identifierWithHighestVersionUpdate : String ?
139
- results. forEach { key, value in
140
- switch value {
141
- case . failure( let error) :
142
- self . log. error ( " Error from version check %{public}@: %{public}@ " , key, error. localizedDescription)
143
- case . success( let versionUpdate) :
144
- if let versionUpdate = versionUpdate, versionUpdate > aggregatedVersionUpdate {
145
+ results. forEach { versionUpdate, identifier in
146
+ if let versionUpdate {
147
+ if versionUpdate > aggregatedVersionUpdate {
145
148
aggregatedVersionUpdate = versionUpdate
146
- identifierWithHighestVersionUpdate = key
149
+ identifierWithHighestVersionUpdate = identifier
147
150
}
151
+ } else {
152
+ self . log. error ( " Version check failed for %{public}@ " , identifier)
148
153
}
149
154
}
150
155
return ( identifierWithHighestVersionUpdate, aggregatedVersionUpdate)
@@ -225,8 +230,8 @@ extension SupportManager {
225
230
fileprivate extension Result where Success == VersionUpdate ? {
226
231
var value : VersionUpdate {
227
232
switch self {
228
- case . failure: return . none
229
- case . success( let val) : return val ?? . none
233
+ case . failure: return . noUpdateNeeded
234
+ case . success( let val) : return val ?? . noUpdateNeeded
230
235
}
231
236
}
232
237
}
0 commit comments