cancelable_retry 0.1.0 copy "cancelable_retry: ^0.1.0" to clipboard
cancelable_retry: ^0.1.0 copied to clipboard

Utility for wrapping an asynchronous function in automatic retry logic with ability to cancel it.

cancelable_retry #

pub package innim lint

Utility for wrapping an asynchronous function in automatic retry logic with ability to cancel it.

Features #

Allows to automatically retry request on some condition. Retry logic implemented with exponential back-off, useful when making requests over network. If you don't need to continue retry - you can cancel requests.

Getting started #

To use this plugin, add cancelable_retry as a dependency in your pubspec.yaml file.

Usage #

Create instance of CancelableRetry and call run():

import 'package:cancelable_retry/cancelable_retry.dart';

final request = CancelableRetry(
    // Provide request function
    () => doSomeRequest(),
    // Set conditions for retry
    retryIf: (result) => result == "retry",
    // Optional:
    // - Define max retry attempts
    maxAttempts: 8,
    // - Define max delay between retries
    maxDelay: const Duration(seconds: 30),
    // - Tune delay between retries
    delayFactor: const Duration(milliseconds: 200),
    randomizationFactor: 0.25,
  );

// Run request
final res = await request.run();

If you want to cancel request and retries, just call cancel():

await request.cancel();
3
likes
0
pub points
58%
popularity

Publisher

verified publisherinnim.ru

Utility for wrapping an asynchronous function in automatic retry logic with ability to cancel it.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

async

More

Packages that depend on cancelable_retry