NPRPC docs

class NPRPCStreamWriter

Swift

final class NPRPCStreamWriter<T> where T : Sendable

The sending end of a stream: the writer half of a client or bidi stream, and what a servant uses to push a server_stream.

Call write(_:) per item, then close(), or abort(errorCode:) on failure. The async write waits for the reader's credits, so a slow reader slows the writer down.

nprpc_swift/Sources/NPRPC/StreamReader.swift:368

Methods

func abort(errorCode: UInt32 = 1)

Ends the stream with an error; the reader's loop throws.

nprpc_swift/Sources/NPRPC/StreamReader.swift:516

func cancel()

Stops the stream from this side, telling the peer it was cancelled.

nprpc_swift/Sources/NPRPC/StreamReader.swift:525

func close()

Ends the stream normally. Later writes throw.

nprpc_swift/Sources/NPRPC/StreamReader.swift:507

func write(_ value: T) throws

Synchronous write (used when no backpressure hook is configured). Throws if the writer is already closed, or if this write discovers the peer's session has died — in the latter case the writer is also marked closed, since the stream can't recover.

nprpc_swift/Sources/NPRPC/StreamReader.swift:423

func write(_ value: T) async throws

Async write that respects credit-based backpressure when available. Falls back to synchronous write if no async hook was configured. Throws under the same conditions as the synchronous write(_:).

Serializes into the writer's reusable buffer and hands it to asyncSendChunk under the lock (no per-chunk snapshot copy). The C++ path copies the payload before returning; we then await only the credit/send completion callback.

nprpc_swift/Sources/NPRPC/StreamReader.swift:466