just_throttle_it 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

just_throttle_it #

A simple throttle library for Dart.

import 'package:just_throttle_it/just_throttle_it.dart';

Throttle.milliseconds(1000, print, ["Throttle World!"]);

Static methods #

There are three methods available for throttling. A value of true will be returned if the function call is successful, and false if the function has been blocked. All methods differ only by the first parameter used to specify timeout values in different formats:

Throttle.seconds(int timeoutSeconds, 
    Function target,
    [List<dynamic> positionalArguments, 
    Map<Symbol, dynamic> namedArguments])
Throttle.milliseconds(int timeoutMs, 
    Function target,
    [List<dynamic> positionalArguments, 
    Map<Symbol, dynamic> namedArguments])
Throttle.duration(Duration timeout, 
    Function target,
    [List<dynamic> positionalArguments, 
    Map<Symbol, dynamic> namedArguments])

To clear a throttled target, allowing the next throttled call to be immediately executed:

Throttle.clear(Function target)

Example #

A quick demonstration can be found in the example directory. To run the example:

pub run example/main.dart

Changelog #

1.0.0 #

  • Initial version of a throttle library.

example/main.dart

import 'dart:async';

import 'package:just_throttle_it/just_throttle_it.dart';

void main() async {
  void printSeconds() => print("Hello World (Throttle.seconds)");
  Throttle.seconds(1, printSeconds); // Will print immediately
  Throttle.seconds(1, printSeconds); // Will not print

  void printMs() => print("Hello World (Throttle.milliseconds)");
  Throttle.milliseconds(500, printMs); // Will print immediately
  Throttle.clear(printMs);
  Throttle.milliseconds(500, printMs); // Will print immediately

  final duration = const Duration(milliseconds: 2000);
  Throttle.duration(duration, print, ["Hello World 1 (Throttle.duration)"]); // Will print immediately
  Throttle.duration(duration, print, ["Hello World 2 (Throttle.duration)"]); // Will not print
  Throttle.duration(duration, print, ["Hello World 3 (Throttle.duration)"]); // Will not print
  Throttle.duration(duration, print, ["Hello World 4 (Throttle.duration)"]); // Will not print
  Throttle.duration(duration, print, ["Hello World 5 (Throttle.duration)"]); // Will not print

  await Future.delayed(duration);
  
  Throttle.duration(duration, print, ["Hello World 6 (Throttle.duration)"]); // Will print immediately
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  just_throttle_it: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:just_throttle_it/just_throttle_it.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on May 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.6.5