NPRPC docs

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) throws -> T)

Created by generated code; deserializer decodes one chunk's payload.

nprpc_swift/Sources/NPRPC/StreamReader.swift:110

Properties

var asyncStream: AsyncThrowingStream<T, Error> { get }

Get the underlying async stream for iteration

nprpc_swift/Sources/NPRPC/StreamReader.swift:123

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:105

Methods

func abandon()

For a stream that never opened: forgets the reader without telling the producer, since there isn't one. Used by generated code.

nprpc_swift/Sources/NPRPC/StreamReader.swift:226

func cancel()

Stops the stream: the local loop throws, and the producer is told to stop.

nprpc_swift/Sources/NPRPC/StreamReader.swift:216

func makeAsyncIterator() -> WindowedIterator

for try await support.

nprpc_swift/Sources/NPRPC/StreamReader.swift:128

Type aliases

typealias Element = T

The item type.

nprpc_swift/Sources/NPRPC/StreamReader.swift:81

Types