Skip to content

Commit 6e60632

Browse files
authored
Use async methods when loading manifests (#8551)
### Motivation: This follows on from my work to convert the registry code to `async` methods. ### Modifications: Switch to using async methods when loading manifests, converting synchronous code to the simpler async equivalents and converting sync API calls to their synchronous versions. ### Result: This resolves several warnings and FIXMEs, makes the code easier to read and generally implements concurrency in a more idiomatic way.
1 parent 26d8417 commit 6e60632

20 files changed

+736
-988
lines changed

Sources/Basics/Concurrency/ConcurrencyHelpers.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,20 @@ extension DispatchQueue {
5959
}
6060
}
6161
}
62+
63+
package func asyncResult<T: Sendable>(_ callback: @escaping @Sendable (Result<T, Error>) -> Void, _ closure: @escaping @Sendable () async throws -> T) {
64+
let completion: @Sendable (Result<T, Error>) -> Void = {
65+
result in self.async {
66+
callback(result)
67+
}
68+
}
69+
70+
Task {
71+
do {
72+
completion(.success(try await closure()))
73+
} catch {
74+
completion(.failure(error))
75+
}
76+
}
77+
}
6278
}

Sources/Commands/PackageCommands/ResetCommands.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ extension SwiftPackageCommand {
2727
}
2828
}
2929

30-
struct PurgeCache: SwiftCommand {
30+
struct PurgeCache: AsyncSwiftCommand {
3131
static let configuration = CommandConfiguration(
3232
abstract: "Purge the global repository cache.")
3333

3434
@OptionGroup(visibility: .hidden)
3535
var globalOptions: GlobalOptions
3636

37-
func run(_ swiftCommandState: SwiftCommandState) throws {
38-
try swiftCommandState.getActiveWorkspace().purgeCache(observabilityScope: swiftCommandState.observabilityScope)
37+
func run(_ swiftCommandState: SwiftCommandState) async throws {
38+
try await swiftCommandState.getActiveWorkspace().purgeCache(observabilityScope: swiftCommandState.observabilityScope)
3939
}
4040
}
4141

0 commit comments

Comments
 (0)