run<T> method

Future<T?> run<T>(
  1. FutureOr<T> action()
)

Implementation

Future<T?> run<T>(FutureOr<T> Function() action) {
  final completer = Completer<T?>();
  if (_timer?.isActive ?? false) {
    _timer?.cancel();
  }

  _timer = Timer(
    duration,
        () async {
      completer.complete(await action());
    },
  );

  return completer.future;
}