observeDuration<T> method Null safety

Future<T> observeDuration<T>(
  1. Future<T> f
)

Observe the duration of the Future f and store it in the corresponding buckets of a histogram with labels.

Implementation

Future<T> observeDuration<T>(Future<T> f) async {
  final stopwatch = Stopwatch()..start();
  try {
    return await f;
  } finally {
    observe(stopwatch.elapsedMicroseconds / Duration.microsecondsPerSecond);
  }
}