Interface CloseableIterator<T>

All Superinterfaces:
AutoCloseable, Closeable, Iterator<T>
All Known Implementing Classes:
PageRowLimitingIterator

public interface CloseableIterator<T> extends Iterator<T>, Closeable
An Iterator with state that must be closed.

Iterators may optionally expose an async-ready signal via waitForReady(). The default returns an immediately-completed listener — for synchronous iterators, Iterator.hasNext() can always be called without blocking on upstream production. Iterators whose hasNext() would otherwise spin or block (e.g. waiting on parser threads, network I/O) should override this so the consumer can yield the calling thread back to its executor and resume when work is available.

  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    Non-blocking single-step advance: returns the next element, or null if none is immediately available (either because upstream is still producing or because the iterator is exhausted).
    Returns a listener that completes when Iterator.hasNext() can be called without blocking on upstream production.

    Methods inherited from interface java.io.Closeable

    close

    Methods inherited from interface java.util.Iterator

    forEachRemaining, hasNext, next, remove
  • Method Details

    • waitForReady

      default SubscribableListener<Void> waitForReady()
      Returns a listener that completes when Iterator.hasNext() can be called without blocking on upstream production. The default — appropriate for synchronous iterators — completes immediately.
    • tryAdvance

      default T tryAdvance()
      Non-blocking single-step advance: returns the next element, or null if none is immediately available (either because upstream is still producing or because the iterator is exhausted). Callers distinguish "not yet" from "EOF" via waitForReady(): a null return paired with an immediately-done waitForReady() means EOF; a null paired with a non-done listener means more data may arrive.

      The default delegates to Iterator.hasNext()/Iterator.next() and is therefore blocking for iterators whose hasNext() blocks. Async iterators should override this to guarantee a non-blocking return so the caller (typically an executor-bound producer loop) can yield its thread instead of pinning it.