diff --git a/Sources/PostgresNIO/New/PostgresRowSequence-multi-decode.swift b/Sources/PostgresNIO/New/PostgresRowSequence-multi-decode.swift index aea721e4..0b3302c1 100644 --- a/Sources/PostgresNIO/New/PostgresRowSequence-multi-decode.swift +++ b/Sources/PostgresNIO/New/PostgresRowSequence-multi-decode.swift @@ -2,91 +2,121 @@ #if swift(>=5.5) && canImport(_Concurrency) extension PostgresRowSequence { - func decode(_: (T0).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode(T0.self, context: context, file: file, line: line) } } - func decode(_: (T0, T1).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6, T7).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13).self, context: context, file: file, line: line) } } - func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { + @inlinable + @_alwaysEmitIntoClient + public func decode(_: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14).Type, context: PostgresDecodingContext, file: String = #file, line: Int = #line) -> AsyncThrowingMapSequence { self.map { row in try row.decode((T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14).self, context: context, file: file, line: line) } diff --git a/Sources/PostgresNIO/New/PostgresRowSequence.swift b/Sources/PostgresNIO/New/PostgresRowSequence.swift index 4a87b452..8159e679 100644 --- a/Sources/PostgresNIO/New/PostgresRowSequence.swift +++ b/Sources/PostgresNIO/New/PostgresRowSequence.swift @@ -5,9 +5,8 @@ import NIOConcurrencyHelpers /// An async sequence of ``PostgresRow``s. /// /// - Note: This is a struct to allow us to move to a move only type easily once they become available. -struct PostgresRowSequence: AsyncSequence { - typealias Element = PostgresRow - typealias AsyncIterator = Iterator +public struct PostgresRowSequence: AsyncSequence { + public typealias Element = PostgresRow final class _Internal { @@ -22,7 +21,7 @@ struct PostgresRowSequence: AsyncSequence { self.consumer.sequenceDeinitialized() } - func makeAsyncIterator() -> Iterator { + func makeAsyncIterator() -> AsyncIterator { self.consumer.makeAsyncIterator() } } @@ -33,14 +32,14 @@ struct PostgresRowSequence: AsyncSequence { self._internal = .init(consumer: consumer) } - func makeAsyncIterator() -> Iterator { + public func makeAsyncIterator() -> AsyncIterator { self._internal.makeAsyncIterator() } } extension PostgresRowSequence { - struct Iterator: AsyncIteratorProtocol { - typealias Element = PostgresRow + public struct AsyncIterator: AsyncIteratorProtocol { + public typealias Element = PostgresRow let _internal: _Internal @@ -48,7 +47,7 @@ extension PostgresRowSequence { self._internal = _Internal(consumer: consumer) } - mutating func next() async throws -> PostgresRow? { + public mutating func next() async throws -> PostgresRow? { try await self._internal.next() } @@ -155,11 +154,11 @@ final class AsyncStreamConsumer { } } - func makeAsyncIterator() -> PostgresRowSequence.Iterator { + func makeAsyncIterator() -> PostgresRowSequence.AsyncIterator { self.lock.withLock { self.state.createAsyncIterator() } - let iterator = PostgresRowSequence.Iterator(consumer: self) + let iterator = PostgresRowSequence.AsyncIterator(consumer: self) return iterator } diff --git a/Tests/IntegrationTests/AsyncTests.swift b/Tests/IntegrationTests/AsyncTests.swift index 593a06e0..691c334f 100644 --- a/Tests/IntegrationTests/AsyncTests.swift +++ b/Tests/IntegrationTests/AsyncTests.swift @@ -33,8 +33,8 @@ final class AsyncPostgresConnectionTests: XCTestCase { try await withTestConnection(on: eventLoop) { connection in let rows = try await connection.query("SELECT generate_series(\(start), \(end));", logger: .psqlTest) var counter = 1 - for try await row in rows { - XCTAssertEqual(try row.decode(Int.self, context: .default), counter) + for try await element in rows.decode(Int.self, context: .default) { + XCTAssertEqual(element, counter) counter += 1 } diff --git a/Tests/PostgresNIOTests/New/PostgresRowSequenceTests.swift b/Tests/PostgresNIOTests/New/PostgresRowSequenceTests.swift index 9e01ff06..6d7bc24b 100644 --- a/Tests/PostgresNIOTests/New/PostgresRowSequenceTests.swift +++ b/Tests/PostgresNIOTests/New/PostgresRowSequenceTests.swift @@ -90,7 +90,7 @@ final class PostgresRowSequenceTests: XCTestCase { let dataRows: [DataRow] = (0..<128).map { [ByteBuffer(integer: Int64($0))] } stream.receive(dataRows) - var iterator: PostgresRowSequence.Iterator? = rowSequence.makeAsyncIterator() + var iterator: PostgresRowSequence.AsyncIterator? = rowSequence.makeAsyncIterator() iterator = nil XCTAssertEqual(dataSource.cancelCount, 1) diff --git a/dev/generate-postgresrowsequence-multi-decode.sh b/dev/generate-postgresrowsequence-multi-decode.sh index eb5ad9a0..284b0049 100755 --- a/dev/generate-postgresrowsequence-multi-decode.sh +++ b/dev/generate-postgresrowsequence-multi-decode.sh @@ -11,9 +11,9 @@ function gen() { echo "" fi - #echo " @inlinable" - #echo " @_alwaysEmitIntoClient" - echo -n " func decode