Package com.apple.foundationdb.async
Interface AsyncIterator<T>
-
- Type Parameters:
T- the type of object yielded bynext()
- All Superinterfaces:
java.util.Iterator<T>
- All Known Subinterfaces:
CloseableAsyncIterator<T>
public interface AsyncIterator<T> extends java.util.Iterator<T>A version ofIteratorthat allows for non-blocking iteration over elements. Calls tonext()will not block ifonHasNext()has been called since the last call tonext()and theCompletableFuturereturned fromonHasNext()has completed.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancel()Cancels any outstanding asynchronous work associated with thisAsyncIterator.booleanhasNext()Blocking call to determine if the sequence contains more elements.Tnext()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.
-
-
-
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 byonHasNext()is ready, the next call tonext()will not block.- Returns:
- a
CompletableFuturethat will be set totrueifnext()would return another element without blocking or tofalseif 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 callingonHasNext().get().- Specified by:
hasNextin interfacejava.util.Iterator<T>- Returns:
trueif there are more elements in the sequence,falseotherwise.- See Also:
onHasNext()
-
next
T next()
Returns the next element in the sequence. This will not block if, since the last call tonext(),onHasNext()was called and the resultingCompletableFuturehas completed or the blocking callhasNext()was called and has returned. It is legal, therefore, to make a call tonext()without a preceding call tohasNext()oronHasNext(), but that invocation ofnext()may block on remote operations.- Specified by:
nextin interfacejava.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 thisAsyncIterator.
-
-