Package com.apple.foundationdb.async
Interface AsyncIterator<T>
- Type Parameters:
T
- the type of object yielded bynext()
- All Superinterfaces:
Iterator<T>
- All Known Subinterfaces:
CloseableAsyncIterator<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 TypeMethodDescriptionvoid
cancel()
Cancels any outstanding asynchronous work associated with thisAsyncIterator
.boolean
hasNext()
Blocking call to determine if the sequence contains more elements.next()
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
CompletableFuture<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()
. -
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 interfaceIterator<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 thisAsyncIterator
.
-