Interface AsyncIterator<T>

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

    public interface AsyncIterator<T>
    extends java.util.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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void cancel()
      Cancels any outstanding asynchronous work associated with this AsyncIterator.
      boolean hasNext()
      Blocking call to determine if the sequence contains more elements.
      T next()
      Returns the next element in the sequence.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> onHasNext()
      Returns a asynchronous signal for the presence of more elements in the sequence.
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
    • Method Detail

      • onHasNext

        java.util.concurrent.CompletableFuture<java.lang.Boolean> 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 java.util.Iterator<T>
        Returns:
        true if there are more elements in the sequence, false otherwise.
        See Also:
        onHasNext()
      • 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 java.util.Iterator<T>
        Returns:
        the next element in the sequence, blocking if necessary.
        Throws:
        java.util.NoSuchElementException - if the sequence has been exhausted.
      • cancel

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