maybe_slow_future 1.0.2 copy "maybe_slow_future: ^1.0.2" to clipboard
maybe_slow_future: ^1.0.2 copied to clipboard

A package addding a "slow future" detection callback.

maybe_slow_future #

pub package codecov Build Status

Add a callback to tell you the future is taking longer than an expected duration to complete.

Usage #

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

dependencies:
  maybe_slow_future: ^1.0.2

Example #

/// Remember to import the package to be able to use the [Future.onSlow] extension method
import 'package:maybe_slow_future/maybe_slow_future.dart';

void main() {
  print('Fetching data...');

  const timeToComplete = Duration(seconds: 5);

  /// simulate a long running operation
  final fetchDataFuture = Future.delayed(timeToComplete, () {
    print('Got data after ${timeToComplete}: Hello World!');
  });

  /// use the extension method [Future.onSlow]
  fetchDataFuture.onSlow(Duration(seconds: 2), () {
    print('Be patient! It might take a while to complete...');
  });

  /// or use the [maybeSlowFuture] function
  maybeSlowFuture(
    actualFuture: fetchDataFuture,
    threshold: Duration(seconds: 3, milliseconds: 500),
    onSlowCallback: () {
      print('This is taking longer than expected...');
    },
  );

  /// output:
  /// Fetching data...
  /// Be patient! It might take awhile to complete...
  /// This is taking longer than expected...
  /// Got data after 0:00:05.000000: Hello World!
}
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A package addding a "slow future" detection callback.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

BSD-3-Clause (LICENSE)

More

Packages that depend on maybe_slow_future