Skip to content

Commit f46f956

Browse files
committed
Reduce usage of callback and dispatch methods in favor of async/await
Remove unused callback API Remove unneeded withChecked*Continuation wrappers Use async/await in more tests
1 parent 1d9f2b9 commit f46f956

18 files changed

+98
-302
lines changed

Sources/PackageRegistry/ChecksumTOFU.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,6 @@ struct PackageVersionChecksumTOFU {
6767
}
6868
}
6969

70-
@available(*, noasync, message: "Use the async alternative")
71-
func validateSourceArchive(
72-
registry: Registry,
73-
package: PackageIdentity.RegistryIdentity,
74-
version: Version,
75-
checksum: String,
76-
timeout: DispatchTimeInterval?,
77-
observabilityScope: ObservabilityScope,
78-
callbackQueue: DispatchQueue,
79-
completion: @escaping @Sendable (Result<Void, Error>) -> Void
80-
) {
81-
callbackQueue.asyncResult(completion) {
82-
try await self.validateSourceArchive(
83-
registry: registry,
84-
package: package,
85-
version: version,
86-
checksum: checksum,
87-
timeout: timeout,
88-
observabilityScope: observabilityScope
89-
)
90-
}
91-
}
92-
9370
private func getExpectedChecksum(
9471
registry: Registry,
9572
package: PackageIdentity.RegistryIdentity,

Sources/PackageRegistry/RegistryClient.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -613,25 +613,6 @@ public final class RegistryClient: AsyncCancellable {
613613
}
614614
}
615615

616-
@available(*, deprecated, message: "Use the async alternative")
617-
public func getAvailableManifests(
618-
package: PackageIdentity,
619-
version: Version,
620-
timeout: DispatchTimeInterval? = .none,
621-
observabilityScope: ObservabilityScope,
622-
callbackQueue: DispatchQueue,
623-
completion: @escaping @Sendable (Result<[String: (toolsVersion: ToolsVersion, content: String?)], Error>) -> Void
624-
) {
625-
callbackQueue.asyncResult(completion) {
626-
try await self.getAvailableManifests(
627-
package: package,
628-
version: version,
629-
timeout: timeout,
630-
observabilityScope: observabilityScope
631-
)
632-
}
633-
}
634-
635616
public func getManifestContent(
636617
package: PackageIdentity,
637618
version: Version,

Sources/PackageRegistry/RegistryDownloadsManager.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,25 +121,6 @@ public class RegistryDownloadsManager: AsyncCancellable {
121121
return try await task.value
122122
}
123123

124-
@available(*, noasync, message: "Use the async alternative")
125-
public func lookup(
126-
package: PackageIdentity,
127-
version: Version,
128-
observabilityScope: ObservabilityScope,
129-
delegateQueue: DispatchQueue,
130-
callbackQueue: DispatchQueue,
131-
completion: @escaping @Sendable (Result<Basics.AbsolutePath, Error>) -> Void
132-
) {
133-
callbackQueue.asyncResult(completion) {
134-
try await self.lookup(
135-
package: package,
136-
version: version,
137-
observabilityScope: observabilityScope,
138-
delegateQueue: delegateQueue
139-
)
140-
}
141-
}
142-
143124
/// Cancel any outstanding requests
144125
public func cancel(deadline: DispatchTime) async throws {
145126
try await self.registryClient.cancel(deadline: deadline)

Sources/PackageRegistry/SignatureValidation.swift

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -350,36 +350,6 @@ struct SignatureValidation {
350350
return signingEntity;
351351
}
352352

353-
354-
@available(*, noasync, message: "Use the async alternative")
355-
func validate(
356-
registry: Registry,
357-
package: PackageIdentity.RegistryIdentity,
358-
version: Version,
359-
toolsVersion: ToolsVersion?,
360-
manifestContent: String,
361-
configuration: RegistryConfiguration.Security.Signing,
362-
timeout: DispatchTimeInterval?,
363-
fileSystem: FileSystem,
364-
observabilityScope: ObservabilityScope,
365-
callbackQueue: DispatchQueue,
366-
completion: @escaping @Sendable (Result<SigningEntity?, Error>) -> Void
367-
) {
368-
callbackQueue.asyncResult(completion) {
369-
try await self.validate(
370-
registry: registry,
371-
package: package,
372-
version: version,
373-
toolsVersion: toolsVersion,
374-
manifestContent: manifestContent,
375-
configuration: configuration,
376-
timeout: timeout,
377-
fileSystem: fileSystem,
378-
observabilityScope: observabilityScope
379-
)
380-
}
381-
}
382-
383353
private func getAndValidateManifestSignature(
384354
registry: Registry,
385355
package: PackageIdentity.RegistryIdentity,

Sources/PackageRegistry/SigningEntityTOFU.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,6 @@ struct PackageSigningEntityTOFU {
7676
)
7777
}
7878

79-
@available(*, noasync, message: "Use the async alternative")
80-
func validate(
81-
registry: Registry,
82-
package: PackageIdentity.RegistryIdentity,
83-
version: Version,
84-
signingEntity: SigningEntity?,
85-
observabilityScope: ObservabilityScope,
86-
completion: @escaping @Sendable (Result<Void, Error>) -> Void
87-
) {
88-
DispatchQueue.sharedConcurrent.asyncResult(completion) {
89-
try await self.validate(
90-
registry: registry,
91-
package: package,
92-
version: version,
93-
signingEntity: signingEntity,
94-
observabilityScope: observabilityScope
95-
)
96-
}
97-
}
98-
9979
private func validateSigningEntity(
10080
registry: Registry,
10181
package: PackageIdentity.RegistryIdentity,

Sources/SourceControl/RepositoryManager.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ public class RepositoryManager: Cancellable {
9797
repository: RepositorySpecifier,
9898
updateStrategy: RepositoryUpdateStrategy,
9999
observabilityScope: ObservabilityScope,
100-
delegateQueue: DispatchQueue,
101-
callbackQueue: DispatchQueue
100+
delegateQueue: DispatchQueue
102101
) async throws -> RepositoryHandle {
103102
try await withCheckedThrowingContinuation { continuation in
104103
self.lookup(
@@ -107,7 +106,7 @@ public class RepositoryManager: Cancellable {
107106
updateStrategy: updateStrategy,
108107
observabilityScope: observabilityScope,
109108
delegateQueue: delegateQueue,
110-
callbackQueue: callbackQueue,
109+
callbackQueue: .sharedConcurrent,
111110
completion: { continuation.resume(with: $0) }
112111
)
113112
}

Sources/Workspace/Workspace+Dependencies.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import func Basics.os_signpost
1919
import struct Basics.RelativePath
2020
import enum Basics.SignpostName
2121
import class Basics.ThreadSafeKeyValueStore
22-
import class Dispatch.DispatchGroup
2322
import struct Dispatch.DispatchTime
2423
import enum Dispatch.DispatchTimeInterval
2524
import struct PackageGraph.Assignment

Sources/Workspace/Workspace+Editing.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ extension Workspace {
105105
repository: repository,
106106
updateStrategy: .never,
107107
observabilityScope: observabilityScope,
108-
delegateQueue: .sharedConcurrent,
109-
callbackQueue: .sharedConcurrent
108+
delegateQueue: .sharedConcurrent
110109
)
111110
let repo = try handle.open()
112111

Sources/Workspace/Workspace+Manifests.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import struct Basics.InternalError
1919
import class Basics.ObservabilityScope
2020
import struct Basics.SwiftVersion
2121
import class Basics.ThreadSafeKeyValueStore
22-
import class Dispatch.DispatchGroup
2322
import struct Dispatch.DispatchTime
2423
import struct OrderedCollections.OrderedDictionary
2524
import struct OrderedCollections.OrderedSet
@@ -1045,17 +1044,13 @@ extension Workspace {
10451044
case .fileSystem:
10461045
return nil
10471046
case .custom:
1048-
let container = try await withCheckedThrowingContinuation { continuation in
1049-
self.packageContainerProvider.getContainer(
1050-
for: package,
1051-
updateStrategy: .never,
1052-
observabilityScope: observabilityScope,
1053-
on: .sharedConcurrent,
1054-
completion: {
1055-
continuation.resume(with: $0)
1056-
}
1057-
)
1058-
}
1047+
let container = try await self.packageContainerProvider.getContainer(
1048+
for: package,
1049+
updateStrategy: .never,
1050+
observabilityScope: observabilityScope,
1051+
on: .sharedConcurrent
1052+
)
1053+
10591054
guard let customContainer = container as? CustomPackageContainer else {
10601055
observabilityScope.emit(error: "invalid custom dependency container: \(container)")
10611056
return nil

Sources/Workspace/Workspace+SourceControl.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ extension Workspace {
178178
repository: repository,
179179
updateStrategy: .never,
180180
observabilityScope: observabilityScope,
181-
delegateQueue: .sharedConcurrent,
182-
callbackQueue: .sharedConcurrent
181+
delegateQueue: .sharedConcurrent
183182
)
184183

185184
// Clone the repository into the checkouts.

Sources/Workspace/Workspace.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,24 +1263,6 @@ extension Workspace {
12631263
return try builder.construct()
12641264
}
12651265

1266-
/// Loads a single package in the context of a previously loaded graph. This can be useful for incremental loading
1267-
/// in a longer-lived program, like an IDE.
1268-
@available(*, noasync, message: "Use the async alternative")
1269-
public func loadPackage(
1270-
with identity: PackageIdentity,
1271-
packageGraph: ModulesGraph,
1272-
observabilityScope: ObservabilityScope,
1273-
completion: @escaping @Sendable (Result<Package, Error>) -> Void
1274-
) {
1275-
DispatchQueue.sharedConcurrent.asyncResult(completion) {
1276-
try await self.loadPackage(
1277-
with: identity,
1278-
packageGraph: packageGraph,
1279-
observabilityScope: observabilityScope
1280-
)
1281-
}
1282-
}
1283-
12841266
public func changeSigningEntityFromVersion(
12851267
package: PackageIdentity,
12861268
version: Version,

Sources/_InternalTestSupport/MockWorkspace.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,12 @@ public final class MockWorkspace {
216216
identity: PackageIdentity(url: url),
217217
kind: .remoteSourceControl(url)
218218
)
219-
let container = try await withCheckedThrowingContinuation { continuation in
220-
containerProvider.getContainer(
221-
for: packageRef,
222-
updateStrategy: .never,
223-
observabilityScope: observability.topScope,
224-
on: .sharedConcurrent,
225-
completion: {
226-
continuation.resume(with: $0)
227-
}
228-
)
229-
}
219+
let container = try await containerProvider.getContainer(
220+
for: packageRef,
221+
updateStrategy: .never,
222+
observabilityScope: observability.topScope,
223+
on: .sharedConcurrent
224+
)
230225
guard let customContainer = container as? CustomPackageContainer else {
231226
throw StringError("invalid custom container: \(container)")
232227
}

Tests/BasicsTests/AsyncProcessTests.swift

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,21 @@ final class AsyncProcessTests: XCTestCase {
6666
}
6767
}
6868

69-
func testPopenLegacyAsync() throws {
69+
func testPopenLegacyAsync() async throws {
7070
#if os(Windows)
7171
let args = ["where.exe", "where"]
7272
let answer = "C:\\Windows\\System32\\where.exe"
7373
#else
7474
let args = ["whoami"]
7575
let answer = NSUserName()
7676
#endif
77-
var popenResult: Result<AsyncProcessResult, Error>?
78-
let group = DispatchGroup()
79-
group.enter()
80-
AsyncProcess.popen(arguments: args) { result in
81-
popenResult = result
82-
group.leave()
83-
}
84-
group.wait()
85-
switch popenResult {
86-
case .success(let processResult):
87-
let output = try processResult.utf8Output()
88-
XCTAssertTrue(output.hasPrefix(answer))
89-
case .failure(let error):
90-
XCTFail("error = \(error)")
91-
case nil:
92-
XCTFail()
77+
let processResult = try await withCheckedThrowingContinuation { continuation in
78+
AsyncProcess.popen(arguments: args) { result in
79+
continuation.resume(with: result)
80+
}
9381
}
82+
let output = try processResult.utf8Output()
83+
XCTAssert(output.hasPrefix(answer))
9484
}
9585

9686
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)

Tests/FunctionalTests/PluginTests.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,7 @@ final class PluginTests: XCTestCase {
550550
)
551551

552552
let toolSearchDirectories = [try UserToolchain.default.swiftCompilerPath.parentDirectory]
553-
let success = try await withCheckedThrowingContinuation { continuation in
554-
plugin.invoke(
553+
let success = try await plugin.invoke(
555554
action: .performCommand(package: package, arguments: arguments),
556555
buildEnvironment: BuildEnvironment(platform: .macOS, configuration: .debug),
557556
scriptRunner: scriptRunner,
@@ -568,12 +567,8 @@ final class PluginTests: XCTestCase {
568567
modulesGraph: packageGraph,
569568
observabilityScope: observability.topScope,
570569
callbackQueue: delegateQueue,
571-
delegate: delegate,
572-
completion: {
573-
continuation.resume(with: $0)
574-
}
575-
)
576-
}
570+
delegate: delegate
571+
)
577572
if expectFailure {
578573
XCTAssertFalse(success, "expected command to fail, but it succeeded", file: file, line: line)
579574
}

0 commit comments

Comments
 (0)