retryLocalCallOperation<T> function

Future<T> retryLocalCallOperation<T>(
  1. Future<T> operation(), {
  2. int maxRetries = 5,
  3. Duration retryDelay = const Duration(seconds: 1),
})

Implementation

Future<T> retryLocalCallOperation<T>(Future<T> Function() operation,
    {int maxRetries = 5,
      Duration retryDelay = const Duration(seconds: 1)}) async {
  int retryCount = 0;
  while (retryCount < maxRetries) {
    try {
      return await operation();
    } catch (e) {
      if (e is SqliteException && e.extendedResultCode == 5) {
        retryCount++;
        await Future.delayed(retryDelay); // Wait before retrying
      } else {
        rethrow; // Exit loop on unexpected errors
      }
    }
  }
  throw Exception(
      'Failed to complete the database operation after $maxRetries retries.');
}