loopRequest method

Future<void> loopRequest({
  1. bool validTest()?,
  2. void onRequest()?,
  3. int count = 3,
  4. Duration delay = const Duration(seconds: 10),
  5. bool immediately = false,
})

Implementation

Future<void> loopRequest({
  bool Function()? validTest,
  void Function()? onRequest,
  int count = 3,
  Duration delay = const Duration(seconds: 10),
  bool immediately = false,
}) async {
  logDebug("$runtimeType loop start");
  var index = 0;
  while (index < count) {
    index++;
    logDebug("$runtimeType loop isClosed:$isClosed");
    if (validTest?.call() ?? !isClosed) {
      if (index == 1 && !immediately) {
        logDebug("$runtimeType loop no immediately");
      } else {
        logDebug("$runtimeType loop ing");
        if (onRequest != null) {
          onRequest.call();
        } else {
          onRequestData();
        }
      }
      await delay.delay();
    } else {
      logDebug("$runtimeType loop break");
      break;
    }
  }
}