RetryConfig class

This class represents an automatic retry configuration.

Exponential BackOff Algorithm and Jitter

Simply increasing the wait time exponentially is still not sufficient to distribute retry timing. In addition to simply increasing the interval exponentially, adding a random number called Jitter is effective. This method allows for even greater flexibility in distributing the timing of retries.

import 'package:twitter_api_v2/twitter_api_v2.dart' as v2;

void main() async {
  final twitter = v2.TwitterApi(
    bearerToken: 'YOUR_TOKEN_HERE',

    retryConfig: v2.RetryConfig(
      maxAttempts: 5,
    ),

    timeout: Duration(seconds: 20),
  );
}

The interval, which increases with the number of retries, is then calculated as follows.

(2 ^ retryCount) + jitter(Random Number between 0 ~ 3)

Remarks

Please note that ArgumentError is always raised if a negative number is passed to the maxAttempts field of RetryConfig.

Constructors

RetryConfig({required int maxAttempts, dynamic onExecute(RetryEvent event)?})
Returns the new instance of RetryConfig.
RetryConfig.ofExponentialBackOff({required int maxAttempts, dynamic onExecute(RetryEvent event)?})
Returns the new instance of RetryConfig of Exponential Back Off.
factory
RetryConfig.ofExponentialBackOffAndJitter({required int maxAttempts, dynamic onExecute(RetryEvent event)?})
Returns the new instance of RetryConfig of Exponential Back Off and Jitter.
factory
RetryConfig.ofRegularIntervals({required int maxAttempts, int intervalInSeconds = 2, dynamic onExecute(RetryEvent event)?})
Returns the new instance of RetryConfig of regular intervals.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
maxAttempts int
Maximum number of retry attempts.
final
onExecute → (dynamic Function(RetryEvent event)?)
A callback function to be called when the retry is executed.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited