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

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

cancelable_retry #

pub package Analyze & Test 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 retry. In such case last result will be returned.

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 retries, just call cancel():

await request.cancel();
3
likes
140
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

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

async

More

Packages that depend on cancelable_retry