queue 1.0.1+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

queue #

Build Status

Easily queue futures and await their values.

This library allows you to send a future to central queue. The queue will execute the futures in the order they are queued and once the future is complete it will return its result.

My use case was to rate limit calls to bluetooth devices. There were multiple bluetooth devices connected that may have different commands being sent from lots of areas in the app. The devices were tripping over themselves and not responding. A stream wasn't the appropriate tool as I needed to get the result back. Hence a library was born.

Alternative use cases could be spidering a website, downloading a number of files, or rate limiting calls to an API.

Usage #

A simple usage example:

import 'package:dart_queue/dart_queue.dart';

main() async {
  //Create the queue container
  final Queue queue = Queue(delay: Duration(milliseconds: 10));
  //Add items to the queue asyncroniously
  queue.add(()=>Future.delayed(Duration(milliseconds: 100)));
  queue.add(()=>Future.delayed(Duration(milliseconds: 10)));
  //Get a result from the future in line with await
  final result = await queue.add(() async {
    await Future.delayed(Duration(milliseconds: 1));
    return "Future Complete";
  //100, 10, 1 will reslove in that order.
  result == "Future Complete"; //true

1.0.1+2 #

  • Improving the readme

1.0.1+1 #

  • Improving the package description

1.0.1 #

  • Removing some console output

1.0.0 #

  • Initial version


import 'package:queue/queue.dart';

Future<void> main() async {
  final queue = Queue(delay: const Duration(milliseconds: 100));

  Future asyncMessage(String message) async {

  unawaited(queue.add(() async {
    await asyncMessage("Message 1");
  }).then((result) => print("Message 1 complete")));

  await queue.add(() async {
    await asyncMessage("Message 2");

  await Future.delayed(const Duration(milliseconds: 500));

  print('Message 2 complete');

  unawaited(queue.add(() async {
    await asyncMessage("Message 3");
    print("awaited message");
    throw Exception("Error");
  }).then((result) => print("Message 3 complete")));

      .add(() async => asyncMessage("Message 4"))
      .then((result) => print("Message 4 complete")));

void unawaited(Future<void> future) {}

Use this package as a library

1. Depend on it

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

  queue: ^1.0.1+2

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:queue/queue.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13

Health issues and suggestions

Document public APIs. (-1 points)

18 out of 18 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
Dev dependencies
extra_pedantic 1.1.1
pedantic any
test ^1.6.0