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 ofIterator
that allows for non-blocking iteration over elements. Calls tonext()
will not block ifonHasNext()
has been called since the last call tonext()
and theCompletableFuture
returned fromonHasNext()
has completed.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
cancel()
Cancels any outstanding asynchronous work associated with thisAsyncIterator
.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.
-
-
-
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
CompletableFuture
that will be set totrue
ifnext()
would return another element without blocking or tofalse
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 callingonHasNext().get()
.- Specified by:
hasNext
in interfacejava.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 tonext()
,onHasNext()
was called and the resultingCompletableFuture
has 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:
next
in 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
.
-
-