Class TimedAsyncIterable
java.lang.Object
com.apple.foundationdb.async.common.TimedAsyncIterable
Wraps an
AsyncIterable so the wall-clock time spent awaiting its elements is measured and reported
once the scan finishes. A range read (an AsyncIterable produced by getRange) has no single
completion to time the way a point read's CompletableFuture does: it is consumed lazily, batch by batch, by
whoever drains it. This wrapper times both ways a consumer can drain it and reports the elapsed nanos to a
LongConsumer exactly once per consumption:
- via
AsyncIterable.iterator(): accumulates the time eachonHasNext/hasNextspends waiting for the next batch and reports the running total when the iterator is exhausted, fails, or is cancelled; - via
AsyncIterable.asList(): times that single future directly (preserving the native, optimized collect path rather than routing it throughAsyncIterable.iterator()).
AsyncIterator wrapper at every site.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AsyncIterable<T> wrap(AsyncIterable<T> iterable, LongConsumer elapsedNanosConsumer) Returns anAsyncIterablethat behaves exactly likeiterablebut reports, once per consumption, the total nanos spent awaiting the scan.
-
Method Details
-
wrap
@Nonnull public static <T> AsyncIterable<T> wrap(@Nonnull AsyncIterable<T> iterable, @Nonnull LongConsumer elapsedNanosConsumer) Returns anAsyncIterablethat behaves exactly likeiterablebut reports, once per consumption, the total nanos spent awaiting the scan. Draining viaAsyncIterable.iterator()reports on exhaustion, error, orAsyncIterator.cancel()(an iterator simply abandoned without any of those never reports); draining viaAsyncIterable.asList()reports when that future completes.- Type Parameters:
T- the element type- Parameters:
iterable- the iterable to timeelapsedNanosConsumer- receives the accumulated await time in nanoseconds- Returns:
- a timing wrapper around
iterable
-