waitAtLeast<T> function

Future<T> waitAtLeast<T>(
  1. Future<T> future, {
  2. Duration delay = const Duration(milliseconds: 1000),
})

Implementation

Future<T> waitAtLeast<T>(Future<T> future,
    {Duration delay = const Duration(milliseconds: 1000)}) async {
  final startedAt = DateTime.now();
  final result = await future;
  final timeTaken = DateTime.now().millisecond - startedAt.millisecond;

  if (timeTaken > delay.inMilliseconds) {
    return result;
  }
  await Future.delayed(delay);
  return result;
}