Compare commits

..
Author SHA1 Message Date
Gwendal Roué fd5822e8f2 Update the Swift Concurrency Guide 2026-12-03 17:03:20 +01:00
Gwendal Roué d6d6ba2032 CHANGELOG 2026-12-03 17:03:20 +01:00
Gwendal Roué 9688ebb447 Async database accesses have sending results 2026-12-03 17:03:20 +01:00
Gwendal Roué 099b59a7df Failing tests for non-sendable values returned from an async database access 2026-12-03 17:03:20 +01:00
Gwendal Roué 4a1bf09e62 Vendor Disconnected from SE-0538
Disconnected will ship with Swift 6.5
2026-12-03 17:03:20 +01:00
2 changed files with 8 additions and 45 deletions

No files matched your search

+3
View File
@@ -21,6 +21,9 @@
/// This is a vendored copy of the `Disconnected` type of the Synchronization
/// module, introduced by SE-0538:
/// <https://github.com/swiftlang/swift-evolution/blob/main/proposals/0538-disconnected.md>
///
/// TODO: Remove this copy, and use the Synchronization type, when the
/// minimum Swift version is 6.5.
struct Disconnected<Value: ~Copyable>: ~Copyable, Sendable {
// This is safe since the only values assigned are sent into `Disconnected`.
nonisolated(unsafe) var _value: Value
@@ -10,23 +10,6 @@ private class NonSendable {
}
}
private class NonSendableRecord:
Codable, Identifiable,
FetchableRecord, PersistableRecord
{
var id: Int64
init(id: Int64) {
self.id = id
}
static func createTable(_ db: Database) throws {
try db.create(table: databaseTableName) { t in
t.autoIncrementedPrimaryKey("id")
}
}
}
// MARK: - Database readers and writers
/// The kinds of database readers whose async methods are tested.
@@ -55,25 +38,21 @@ private func withTemporaryDirectory(
private func withDatabaseReader(
_ kind: ReaderKind,
setup: (any DatabaseWriter) async throws -> Void = { _ in },
test: (any DatabaseReader) async throws -> Void
_ body: (any DatabaseReader) async throws -> Void
) async throws {
switch kind {
case .queue:
let dbQueue = try DatabaseQueue()
try await setup(dbQueue)
try await test(dbQueue)
try await body(DatabaseQueue())
case .pool, .snapshot, .snapshotPool:
try await withTemporaryDirectory { directoryURL in
let dbPool = try DatabasePool(path: directoryURL.appending(path: "db.sqlite").path)
try await setup(dbPool)
switch kind {
case .pool:
try await test(dbPool)
try await body(dbPool)
case .snapshot:
try await test(dbPool.makeSnapshot())
try await body(dbPool.makeSnapshot())
case .snapshotPool:
try await test(dbPool.makeSnapshotPool())
try await body(dbPool.makeSnapshotPool())
case .queue:
fatalError()
}
@@ -232,22 +211,3 @@ private func withDatabaseWriter(
}
}
}
// MARK: - Non-Sendable record results
@Suite struct NonSendableRecordResultTests {
@Test(arguments: ReaderKind.allCases)
func non_sendable_record_returned_from_read(kind: ReaderKind) async throws {
try await withDatabaseReader(kind) { writer in
try await writer.write { db in
try NonSendableRecord.createTable(db)
try NonSendableRecord(id: 1).insert(db)
}
} test: { reader in
let record = try await reader.read { db in
try NonSendableRecord.find(db, id: 1)
}
#expect(record.id == 1)
}
}
}