retryable 1.0.0 icon indicating copy to clipboard operation
retryable: ^1.0.0 copied to clipboard

make operation retryable.

Retryable, make operation retryable. #

Usage #

void main(){
    final cancelable = Cancelable();
    int i = -1;
    const int exceptionI = 0;
    const int expectI = 9;
    final timer = Timer.periodic(
      const Duration(seconds: 1),
      (timer) {
        i = Random().nextInt(10);
      },
    );
    try {
      final res = await retry<int>(
        () async {
          print('$i');
          if (i == exceptionI) {
            throw Exception('exit');
          }
          if (i != expectI) {
            throw Exception('retryable');
          }
          return i;
        },
        cancelable: cancelable,
        cancel: () async {
          timer.cancel();
        },
        able: (i, e) async {
          if (e is! Exception || e.toString().contains('retryable') == false) {
            throw e;
          }
          await Future.delayed(const Duration(seconds: 1));
        },
      );
      print('$res');
    } catch (e) {
      print(e.toString());
    }
}
0
likes
110
pub points
26%
popularity

Publisher

unverified uploader

make operation retryable.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.BSD-3-Clause (LICENSE)

Dependencies

cancelable

More

Packages that depend on retryable