maybe_slow_future 1.0.2

Dart native js
Flutter Android iOS web

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
100
pub points
0%
popularity

A package addding a "slow future" detection callback.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

Uploader

6220119@gmail.com

License

BSD (LICENSE)

More

Packages that depend on maybe_slow_future