Interface AsyncIterator<T>

Type Parameters:
T - the type of object yielded by next()
All Superinterfaces:
Iterator<T>
All Known Subinterfaces:
CloseableAsyncIterator<T>

public interface AsyncIterator<T> extends Iterator<T>
A version of Iterator that allows for non-blocking iteration over elements. Calls to next() will not block if onHasNext() has been called since the last call to next() and the CompletableFuture returned from onHasNext() has completed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cancels any outstanding asynchronous work associated with this AsyncIterator.
    boolean
    Blocking call to determine if the sequence contains more elements.
    Returns the next element in the sequence.
    Returns a asynchronous signal for the presence of more elements in the sequence.

    Methods inherited from interface java.util.Iterator

    forEachRemaining, remove
  • Method Details

    • onHasNext

      Returns a asynchronous signal for the presence of more elements in the sequence. Once the future returned by onHasNext() is ready, the next call to next() will not block.
      Returns:
      a CompletableFuture that will be set to true if next() would return another element without blocking or to false if there are no more elements in the sequence.
    • hasNext

      boolean hasNext()
      Blocking call to determine if the sequence contains more elements. This call is equivalent to calling onHasNext().get().
      Specified by:
      hasNext in interface Iterator<T>
      Returns:
      true if there are more elements in the sequence, false otherwise.
      See Also:
    • next

      T next()
      Returns the next element in the sequence. This will not block if, since the last call to next(), onHasNext() was called and the resulting CompletableFuture has completed or the blocking call hasNext() was called and has returned. It is legal, therefore, to make a call to next() without a preceding call to hasNext() or onHasNext(), but that invocation of next() may block on remote operations.
      Specified by:
      next in interface Iterator<T>
      Returns:
      the next element in the sequence, blocking if necessary.
      Throws:
      NoSuchElementException - if the sequence has been exhausted.
    • cancel

      void cancel()
      Cancels any outstanding asynchronous work associated with this AsyncIterator.