dart-neats icon indicating copy to clipboard operation
dart-neats copied to clipboard

[retry] Add onAttempt callback to RetryOptions for logging

Open NJashwanth opened this issue 3 weeks ago • 1 comments

This PR for the retry package introduces a new optional onAttempt callback to the RetryOptions.retry() method. This callback is called on every retry attempt and receives the current attempt number. It is intended for logging, metrics, or instrumentation purposes without affecting the actual retry logic.

Existing behavior of fn() callbacks remains unchanged, ensuring full backward compatibility.

Example Usage

final r = RetryOptions(maxAttempts: 3);

await r.retry(
  () async {
    // Your retry logic here
  },
  onAttempt: (attempt) {
    print('Attempt #$attempt');
  },
);

NJashwanth avatar Dec 04 '25 01:12 NJashwanth