Skip to content

Commit 99fbf80

Browse files
committed
Nicer workaround for async let/github concurrency error, requires macOS 15
1 parent 2beba3d commit 99fbf80

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import PackageDescription
1919
let package = Package(
2020
name: "SPI-Server",
2121
platforms: [
22-
.macOS(.v13)
22+
.macOS(.v15)
2323
],
2424
products: [
2525
.executable(name: "Run", targets: ["Run"]),

Sources/App/Commands/Ingestion.swift

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,14 @@ enum Ingestion {
262262
throw Github.Error.requestFailed(.internalServerError)
263263
}
264264

265-
// Work-around for
266-
// Sending 'github' into async let risks causing data races between async let uses and local uses
267-
// if we declare
268-
// @Dependency(\.github) var github
269-
// up front. It needs to be local to each task instead.
270-
func _fetchMetadata() async throws(Github.Error) -> Github.Metadata {
271-
@Dependency(\.github) var github
272-
return try await github.fetchMetadata(owner, repository)
273-
}
274-
func _fetchLicense() async -> Github.License? {
275-
@Dependency(\.github) var github
276-
return await github.fetchLicense(owner, repository)
277-
}
278-
279-
async let metadata = try await _fetchMetadata()
280-
async let license = await _fetchLicense()
265+
// Need to pull in github functions individually, because otherwise the `async let` will trigger a
266+
// concurrency error if github gets used more than once:
267+
// Sending 'github' into async let risks causing data races between async let uses and local uses
268+
@Dependency(\.github.fetchMetadata) var fetchMetadata
269+
@Dependency(\.github.fetchLicense) var fetchLicense
270+
271+
async let metadata = try await fetchMetadata(owner, repository)
272+
async let license = await fetchLicense(owner, repository)
281273
async let readme = await Current.fetchReadme(client, owner, repository)
282274

283275
do {

0 commit comments

Comments
 (0)