Skip to content

Use tsc_await rather than await #3037

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

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ private final class ContainerProvider {
}

// Otherwise, fetch the container synchronously.
let container = try await { provider.getContainer(for: identifier, skipUpdate: skipUpdate, completion: $0) }
let container = try tsc_await { provider.getContainer(for: identifier, skipUpdate: skipUpdate, completion: $0) }
let pubGrubContainer = PubGrubPackageContainer(container, pinsMap: pinsMap)
self._fetchedContainers[identifier] = .success(pubGrubContainer)
return pubGrubContainer
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMPackageEditor/PackageEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public final class PackageEditor {
} else {
// Otherwise, first lookup the dependency.
let spec = RepositorySpecifier(url: options.url)
let handle = try await{ context.repositoryManager.lookup(repository: spec, completion: $0) }
let handle = try tsc_await{ context.repositoryManager.lookup(repository: spec, completion: $0) }
let repo = try handle.open()

// Compute the requirement.
Expand Down
10 changes: 5 additions & 5 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ extension Workspace {
// Otherwise, create a checkout at the destination from our repository store.
//
// Get handle to the repository.
let handle = try await {
let handle = try tsc_await {
repositoryManager.lookup(repository: dependency.packageRef.repository, skipUpdate: true, completion: $0)
}
let repo = try handle.open()
Expand Down Expand Up @@ -1579,7 +1579,7 @@ extension Workspace {
// automatically manage the parallelism.
let pins = pinsStore.pins.map({ $0 })
DispatchQueue.concurrentPerform(iterations: pins.count) { idx in
_ = try? await {
_ = try? tsc_await {
containerProvider.getContainer(for: pins[idx].packageRef, skipUpdate: true, completion: $0)
}
}
Expand Down Expand Up @@ -2022,7 +2022,7 @@ extension Workspace {

case .revision(let identifier):
// Get the latest revision from the container.
let container = try await {
let container = try tsc_await {
containerProvider.getContainer(for: packageRef, skipUpdate: true, completion: $0)
} as! RepositoryPackageContainer
var revision = try container.getRevision(forIdentifier: identifier)
Expand Down Expand Up @@ -2249,7 +2249,7 @@ extension Workspace {
}

// If not, we need to get the repository from the checkouts.
let handle = try await {
let handle = try tsc_await {
repositoryManager.lookup(repository: package.repository, skipUpdate: true, completion: $0)
}

Expand Down Expand Up @@ -2320,7 +2320,7 @@ extension Workspace {
// way to get it back out of the resolver which is very
// annoying. Maybe we should make an SPI on the provider for
// this?
let container = try await { containerProvider.getContainer(for: package, skipUpdate: true, completion: $0) } as! RepositoryPackageContainer
let container = try tsc_await { containerProvider.getContainer(for: package, skipUpdate: true, completion: $0) } as! RepositoryPackageContainer
guard let tag = container.getTag(for: version) else {
throw StringError("Internal error: please file a bug at https://bugs.swift.org with this info -- unable to get tag for \(package) \(version); available versions \(container.reversedVersions)")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abertelrud @neonichu beyond the scope of this PR, but the fact the code [in the above three files] is blocking on what looks to be I/O seems like its worth a deeper look. at a high-level, "asynchronity" should bubble all the way to the "top" and only the UI/CLI call sites should block or use a dispatch queue to synchronize the "effects" where appropriate. Usage in tests is fine to simplify.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,43 @@ final class PackageCollectionProfileStorageTest: XCTestCase {
let sources = makeMockSources()

try sources.forEach { source in
_ = try await { callback in storage.add(source: source, order: nil, to: .default, callback: callback) }
_ = try tsc_await { callback in storage.add(source: source, order: nil, to: .default, callback: callback) }
}

let profiles = try await { callback in storage.listProfiles(callback: callback) }
let profiles = try tsc_await { callback in storage.listProfiles(callback: callback) }
XCTAssertEqual(profiles.count, 1, "profiles should match")

do {
let list = try await { callback in storage.listSources(in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, sources.count, "collections should match")
}

let remove = sources.enumerated().filter { index, _ in index % 2 == 0 }.map { $1 }
try remove.forEach { source in
_ = try await { callback in storage.remove(source: source, from: .default, callback: callback) }
_ = try tsc_await { callback in storage.remove(source: source, from: .default, callback: callback) }
}

do {
let list = try await { callback in storage.listSources(in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, sources.count - remove.count, "collections should match")
}

let remaining = sources.filter { !remove.contains($0) }
try sources.forEach { source in
XCTAssertEqual(try await { callback in storage.exists(source: source, in: .default, callback: callback) }, remaining.contains(source))
XCTAssertEqual(try await { callback in storage.exists(source: source, in: nil, callback: callback) }, remaining.contains(source))
XCTAssertEqual(try tsc_await { callback in storage.exists(source: source, in: .default, callback: callback) }, remaining.contains(source))
XCTAssertEqual(try tsc_await { callback in storage.exists(source: source, in: nil, callback: callback) }, remaining.contains(source))
}

do {
_ = try await { callback in storage.move(source: remaining.last!, to: 0, in: .default, callback: callback) }
let list = try await { callback in storage.listSources(in: .default, callback: callback) }
_ = try tsc_await { callback in storage.move(source: remaining.last!, to: 0, in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, remaining.count, "collections should match")
XCTAssertEqual(list.first, remaining.last, "item should match")
}

do {
_ = try await { callback in storage.move(source: remaining.last!, to: remaining.count - 1, in: .default, callback: callback) }
let list = try await { callback in storage.listSources(in: .default, callback: callback) }
_ = try tsc_await { callback in storage.move(source: remaining.last!, to: remaining.count - 1, in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, remaining.count, "collections should match")
XCTAssertEqual(list.last, remaining.last, "item should match")
}
Expand All @@ -92,19 +92,19 @@ final class PackageCollectionProfileStorageTest: XCTestCase {
let sources = makeMockSources()

try sources.forEach { source in
_ = try await { callback in storage.add(source: source, order: nil, to: .default, callback: callback) }
_ = try tsc_await { callback in storage.add(source: source, order: nil, to: .default, callback: callback) }
}

do {
let list = try await { callback in storage.listSources(in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, sources.count, "collections should match")
}

try mockFileSystem.removeFileTree(storage.path)
XCTAssertFalse(mockFileSystem.exists(storage.path), "expected file to be deleted")

do {
let list = try await { callback in storage.listSources(in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, 0, "collections should match")
}
}
Expand All @@ -116,11 +116,11 @@ final class PackageCollectionProfileStorageTest: XCTestCase {
let sources = makeMockSources()

try sources.forEach { source in
_ = try await { callback in storage.add(source: source, order: nil, to: .default, callback: callback) }
_ = try tsc_await { callback in storage.add(source: source, order: nil, to: .default, callback: callback) }
}

do {
let list = try await { callback in storage.listSources(in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, sources.count, "collections should match")
}

Expand All @@ -129,7 +129,7 @@ final class PackageCollectionProfileStorageTest: XCTestCase {
XCTAssertEqual(buffer.count, 0, "expected file to be empty")

do {
let list = try await { callback in storage.listSources(in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, 0, "collections should match")
}
}
Expand All @@ -141,10 +141,10 @@ final class PackageCollectionProfileStorageTest: XCTestCase {
let sources = makeMockSources()

try sources.forEach { source in
_ = try await { callback in storage.add(source: source, order: nil, to: .default, callback: callback) }
_ = try tsc_await { callback in storage.add(source: source, order: nil, to: .default, callback: callback) }
}

let list = try await { callback in storage.listSources(in: .default, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: .default, callback: callback) }
XCTAssertEqual(list.count, sources.count, "collections should match")

try mockFileSystem.writeFileContents(storage.path, bytes: ByteString("{".utf8))
Expand All @@ -153,7 +153,7 @@ final class PackageCollectionProfileStorageTest: XCTestCase {
XCTAssertNotEqual(buffer.count, 0, "expected file to be written")
print(buffer)

XCTAssertThrowsError(try await { callback in storage.listSources(in: .default, callback: callback) }, "expected an error", { error in
XCTAssertThrowsError(try tsc_await { callback in storage.listSources(in: .default, callback: callback) }, "expected an error", { error in
XCTAssert(error is DecodingError, "expected error to match")
})
}
Expand All @@ -166,30 +166,30 @@ final class PackageCollectionProfileStorageTest: XCTestCase {
let sources = makeMockSources()

try sources.forEach { source in
_ = try await { callback in storage.add(source: source, order: nil, to: profile, callback: callback) }
_ = try tsc_await { callback in storage.add(source: source, order: nil, to: profile, callback: callback) }
}

let profiles = try await { callback in storage.listProfiles(callback: callback) }
let profiles = try tsc_await { callback in storage.listProfiles(callback: callback) }
XCTAssertEqual(profiles.count, 1, "profiles should match")

do {
let list = try await { callback in storage.listSources(in: profile, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: profile, callback: callback) }
XCTAssertEqual(list.count, sources.count, "sources should match")
}

let remove = sources.enumerated().filter { index, _ in index % 2 == 0 }.map { $1 }
try remove.forEach { source in
_ = try await { callback in storage.remove(source: source, from: profile, callback: callback) }
_ = try tsc_await { callback in storage.remove(source: source, from: profile, callback: callback) }
}

do {
let list = try await { callback in storage.listSources(in: profile, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: profile, callback: callback) }
XCTAssertEqual(list.count, sources.count - remove.count, "sources should match")
}

try sources.forEach { source in
XCTAssertEqual(try await { callback in storage.exists(source: source, in: profile, callback: callback) }, !remove.contains(source))
XCTAssertEqual(try await { callback in storage.exists(source: source, in: nil, callback: callback) }, !remove.contains(source))
XCTAssertEqual(try tsc_await { callback in storage.exists(source: source, in: profile, callback: callback) }, !remove.contains(source))
XCTAssertEqual(try tsc_await { callback in storage.exists(source: source, in: nil, callback: callback) }, !remove.contains(source))
}

let buffer = try mockFileSystem.readFileContents(storage.path)
Expand All @@ -207,15 +207,15 @@ final class PackageCollectionProfileStorageTest: XCTestCase {

try sources.enumerated().forEach { index, source in
let profile = index % 2 == 0 ? Array(profiles.keys)[0] : Array(profiles.keys)[1]
_ = try await { callback in storage.add(source: source, order: nil, to: profile, callback: callback) }
_ = try tsc_await { callback in storage.add(source: source, order: nil, to: profile, callback: callback) }
profiles[profile]?.append(source)
}

let list = try await { callback in storage.listProfiles(callback: callback) }
let list = try tsc_await { callback in storage.listProfiles(callback: callback) }
XCTAssertEqual(list.count, profiles.count, "list count should match")

try profiles.forEach { profile, profileCollections in
let list = try await { callback in storage.listSources(in: profile, callback: callback) }
let list = try tsc_await { callback in storage.listSources(in: profile, callback: callback) }
XCTAssertEqual(list.count, profileCollections.count, "list count should match")
}

Expand Down
Loading