NyaruDocumentStream

public struct NyaruDocumentStream<T> : AsyncSequence, Sendable where T : Decodable, T : Encodable, T : Sendable

A pull-based AsyncSequence that yields documents one by one without materialising the entire collection in memory.

The iterator fetches documents in bounded batches from the storage engine. Each batch is decoded lazily as the consumer calls next(). When the batch is exhausted, the next batch is fetched from the collection actor.

Memory usage is bounded by one batch (batchSize documents).

Note

This replaces the earlier AsyncThrowingStream-based approach whose unbounded buffer allowed a fast producer to materialise the whole collection behind a slow consumer, defeating the purpose of streaming.
  • Declaration

    Swift

    public typealias Element = T
  • Creates the iterator for this stream.

    Declaration

    Swift

    public func makeAsyncIterator() -> Iterator

    Return Value

    An Iterator ready to yield documents.

  • The pull-based iterator that fetches documents in bounded batches.

    See more

    Declaration

    Swift

    public struct Iterator : AsyncIteratorProtocol