Skip to content

Commit c54c006

Browse files
authored
Add Sendable checking (#242)
1 parent 495dec9 commit c54c006

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

Sources/PostgresNIO/Connection/PostgresConnection.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,7 @@ private extension String {
566566
}
567567
}
568568
}
569+
570+
#if swift(>=5.6)
571+
extension PostgresConnection: @unchecked Sendable {}
572+
#endif

Sources/PostgresNIO/Data/PostgresData.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if swift(>=5.6)
2+
@preconcurrency import NIOCore
3+
#else
14
import NIOCore
5+
#endif
26
import Foundation
37

48
public struct PostgresData: CustomStringConvertible, CustomDebugStringConvertible {
@@ -112,3 +116,7 @@ extension PostgresData: PostgresDataConvertible {
112116
return self
113117
}
114118
}
119+
120+
#if swift(>=5.6)
121+
extension PostgresData: Sendable {}
122+
#endif

Sources/PostgresNIO/Data/PostgresDataType.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ extension PostgresFormat: CustomStringConvertible {
1717
}
1818
}
1919

20+
#if swift(>=5.6)
21+
extension PostgresFormat: Sendable {}
22+
#endif
23+
24+
2025
// TODO: The Codable conformance does not make any sense. Let's remove this with next major break.
2126
extension PostgresFormat: Codable {}
2227

@@ -233,6 +238,10 @@ public struct PostgresDataType: RawRepresentable, Hashable, CustomStringConverti
233238
}
234239
}
235240

241+
#if swift(>=5.6)
242+
extension PostgresDataType: Sendable {}
243+
#endif
244+
236245
// TODO: The Codable conformance does not make any sense. Let's remove this with next major break.
237246
extension PostgresDataType: Codable {}
238247

Sources/PostgresNIO/Data/PostgresRow.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if swift(>=5.6)
2+
@preconcurrency import NIOCore
3+
#else
14
import NIOCore
5+
#endif
26
import class Foundation.JSONDecoder
37

48
/// `PostgresRow` represents a single table row that is received from the server for a query or a prepared statement.
@@ -311,3 +315,11 @@ extension PostgresRow: CustomStringConvertible {
311315
return row.description
312316
}
313317
}
318+
319+
#if swift(>=5.6)
320+
extension PostgresRow: Sendable {}
321+
322+
extension PostgresRandomAccessRow: Sendable {}
323+
#endif
324+
325+

Sources/PostgresNIO/New/Messages/RowDescription.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,7 @@ struct RowDescription: PostgresBackendMessage.PayloadDecodable, Equatable {
7676
return RowDescription(columns: result)
7777
}
7878
}
79+
80+
#if swift(>=5.6)
81+
extension RowDescription.Column: Sendable {}
82+
#endif

Sources/PostgresNIO/New/PSQLRowStream.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,8 @@ protocol PSQLRowsDataSource {
396396
func cancel(for stream: PSQLRowStream)
397397

398398
}
399+
400+
#if swift(>=5.6)
401+
// Thread safety is guaranteed in the RowStream through dispatching onto the NIO EventLoop.
402+
extension PSQLRowStream: @unchecked Sendable {}
403+
#endif

Sources/PostgresNIO/New/PostgresCell.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if swift(>=5.6)
2+
@preconcurrency import NIOCore
3+
#else
14
import NIOCore
5+
#endif
26

37
public struct PostgresCell: Equatable {
48
public var bytes: ByteBuffer?
@@ -49,3 +53,7 @@ extension PostgresCell {
4953
}
5054
}
5155
}
56+
57+
#if swift(>=5.6)
58+
extension PostgresCell: Sendable {}
59+
#endif

0 commit comments

Comments
 (0)