Class TimedAsyncIterable

java.lang.Object
com.apple.foundationdb.async.common.TimedAsyncIterable

public final class TimedAsyncIterable extends Object
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 each onHasNext/hasNext spends 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 through AsyncIterable.iterator()).
It exists so a read listener can turn "time this range scan" into a single call rather than re-implementing an AsyncIterator wrapper at every site.
  • Method Details

    • wrap

      @Nonnull public static <T> AsyncIterable<T> wrap(@Nonnull AsyncIterable<T> iterable, @Nonnull LongConsumer elapsedNanosConsumer)
      Returns an AsyncIterable that behaves exactly like iterable but reports, once per consumption, the total nanos spent awaiting the scan. Draining via AsyncIterable.iterator() reports on exhaustion, error, or AsyncIterator.cancel() (an iterator simply abandoned without any of those never reports); draining via AsyncIterable.asList() reports when that future completes.
      Type Parameters:
      T - the element type
      Parameters:
      iterable - the iterable to time
      elapsedNanosConsumer - receives the accumulated await time in nanoseconds
      Returns:
      a timing wrapper around iterable