class NPRPCStreamReader
Swift
class NPRPCStreamReader<T> where T : Sendable
The receiving end of a stream: what a proxy's server_stream method
returns, and what a servant's client_stream method receives.
Iterate it with for try await; the loop ends when the producer
finishes and throws if it fails:
for try await post in try blog.feed(limit: 10) {
show(post)
}
Flow control is automatic: the reader grants the producer more credits as items are consumed.
nprpc_swift/Sources/NPRPC/StreamReader.swift:79
Constructors
init(streamId: UInt64, buffer: FlatBuffer, deserializer: @escaping (UnsafeRawPointer, Int) -> T)
Created by generated code; deserializer decodes one chunk's payload.
nprpc_swift/Sources/NPRPC/StreamReader.swift:103
Properties
var asyncStream: AsyncThrowingStream<T, Error> { get }
Get the underlying async stream for iteration
nprpc_swift/Sources/NPRPC/StreamReader.swift:116
var onFirstAccess: (@Sendable () -> Void)?
Fired once when the consumer first enters next() (before awaiting a
chunk). Used by stream-init exception probing on the servant side.
nprpc_swift/Sources/NPRPC/StreamReader.swift:98
Methods
func cancel()
Cancel the stream
nprpc_swift/Sources/NPRPC/StreamReader.swift:193
func makeAsyncIterator() -> WindowedIterator
for try await support.
nprpc_swift/Sources/NPRPC/StreamReader.swift:121
Type aliases
typealias Element = T
The item type.
nprpc_swift/Sources/NPRPC/StreamReader.swift:81
Types
NPRPCStreamReader.WindowedIterator struct
Custom iterator that sends the window update after consuming a chunk, i.e. after base.next() returns the value. This is the correct backpressure pattern: credit for chunk N is granted once Swift has received it, not speculatively before requesting N+1. Calling windowUpdateFn before the await on base.next() — even when the buffer already holds data — created a suspension-point race on single-core hosts that caused the iterator to miss the final chunk.