Interface CloseableIterator<T>
- All Superinterfaces:
AutoCloseable,Closeable,Iterator<T>
- All Known Implementing Classes:
PageRowLimitingIterator
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 TypeMethodDescriptiondefault TNon-blocking single-step advance: returns the next element, ornullif none is immediately available (either because upstream is still producing or because the iterator is exhausted).default SubscribableListener<Void> Returns a listener that completes whenIterator.hasNext()can be called without blocking on upstream production.Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
waitForReady
Returns a listener that completes whenIterator.hasNext()can be called without blocking on upstream production. The default — appropriate for synchronous iterators — completes immediately. -
tryAdvance
Non-blocking single-step advance: returns the next element, ornullif none is immediately available (either because upstream is still producing or because the iterator is exhausted). Callers distinguish "not yet" from "EOF" viawaitForReady(): anullreturn paired with an immediately-donewaitForReady()means EOF; anullpaired with a non-done listener means more data may arrive.The default delegates to
Iterator.hasNext()/Iterator.next()and is therefore blocking for iterators whosehasNext()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.
-