Skip to content
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
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import PackageDescription

#if compiler(>=6.1)
let swiftSettings: [SwiftSetting] = []
let swiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("NonisolatedNonsendingByDefault")
]
#else
let swiftSettings: [SwiftSetting] = [
// Sadly the 6.0 compiler concurrency checker finds false positives.
Expand Down
6 changes: 3 additions & 3 deletions Sources/ConnectionPoolModule/ConnectionPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -578,20 +578,20 @@ protocol TaskGroupProtocol {
// We need to call this `addTask_` because some Swift versions define this
// under exactly this name and others have different attributes. So let's pick
// a name that doesn't clash anywhere and implement it using the standard `addTask`.
mutating func addTask_(operation: @escaping @Sendable () async -> Void)
mutating func addTask_(operation: @isolated(any) @escaping @Sendable () async -> Void)
}

@available(macOS 14.0, iOS 17.0, tvOS 17.0, watchOS 10.0, *)
extension DiscardingTaskGroup: TaskGroupProtocol {
@inlinable
mutating func addTask_(operation: @escaping @Sendable () async -> Void) {
mutating func addTask_(operation: @isolated(any) @escaping @Sendable () async -> Void) {
self.addTask(priority: nil, operation: operation)
}
}

extension TaskGroup<Void>: TaskGroupProtocol {
@inlinable
mutating func addTask_(operation: @escaping @Sendable () async -> Void) {
mutating func addTask_(operation: @isolated(any) @escaping @Sendable () async -> Void) {
self.addTask(priority: nil, operation: operation)
}
}
16 changes: 14 additions & 2 deletions Sources/PostgresNIO/New/PostgresNotificationSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ public struct PostgresNotification: Sendable {
public struct PostgresNotificationSequence: AsyncSequence, Sendable {
public typealias Element = PostgresNotification

let base: AsyncThrowingStream<PostgresNotification, Error>
let base: AsyncThrowingStream<PostgresNotification, any Error>

public func makeAsyncIterator() -> AsyncIterator {
AsyncIterator(base: self.base.makeAsyncIterator())
}

public struct AsyncIterator: AsyncIteratorProtocol {
var base: AsyncThrowingStream<PostgresNotification, Error>.AsyncIterator
var base: AsyncThrowingStream<PostgresNotification, any Error>.AsyncIterator

#if compiler(>=6.2)
@concurrent
public mutating func next() async throws -> Element? {
try await self.base.next()
}
#else
public mutating func next() async throws -> Element? {
try await self.base.next()
}
#endif

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Self.Failure) -> Element? {
try await self.base.next(isolation: actor)
}
}
}

Expand Down
35 changes: 34 additions & 1 deletion Sources/PostgresNIO/New/PostgresRowSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public struct PostgresRowSequence: AsyncSequence, Sendable {
extension PostgresRowSequence {
public struct AsyncIterator: AsyncIteratorProtocol {
public typealias Element = PostgresRow
public typealias Failure = any Error

let backing: BackingSequence.AsyncIterator

Expand All @@ -43,7 +44,9 @@ extension PostgresRowSequence {
self.columns = columns
}

public mutating func next() async throws -> PostgresRow? {
#if compiler(>=6.2)
@concurrent
public mutating func next() async throws -> Element? {
if let dataRow = try await self.backing.next() {
return PostgresRow(
data: dataRow,
Expand All @@ -53,6 +56,36 @@ extension PostgresRowSequence {
}
return nil
}
#else
public mutating func next() async throws -> Element? {
if let dataRow = try await self.backing.next() {
return PostgresRow(
data: dataRow,
lookupTable: self.lookupTable,
columns: self.columns
)
}
return nil
}
#endif

@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Self.Failure) -> PostgresRow? {
// Since the underlying NIOThrowingAsyncSequenceProducer<DataRow, Error, AdaptiveRowBuffer, PSQLRowStream>.AsyncIterator
// does not supported the next(isolation:) call yet, we will hop here back and forth.
struct UnsafeTransfer: @unchecked Sendable {
var backing: BackingSequence.AsyncIterator
}
let unsafeTransfer = UnsafeTransfer(backing: self.backing)
if let dataRow = try await unsafeTransfer.backing.next() {
return PostgresRow(
data: dataRow,
lookupTable: self.lookupTable,
columns: self.columns
)
}
return nil
}
}
}

Expand Down
Loading