async_message_queue_controller 0.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 46

AsyncMessageQueueProcessor

A simple controller that processes a message payload queue asynchronously.

Useful when needing to process asynchronously a series of messages with predefined payload type, and those processes should be sequential.

For instance, manage several file uploads in a Flutter app, and be able to suspend the queue when the connectivity is lost.

Usage

A simple usage example:

import 'package:async_message_queue_controller/async_message_queue_controller.dart';
import "dart:async";

/// The callback used by the controller to "process" a message/payload
/// Here the payload is a simple string, an simulates a heavy process
/// lasting 1 second.

Future<Map<String,String>> process(String msg){
  return new Future.delayed(const Duration(seconds: 1), () => {'OK':' Processed msg : $msg'});
}


void main() async {

  var mqc = new AsyncMessageQueueController<String, Map<String,String>>(process);


  Stream<Map<String, String>> s = mqc.start();

  mqc.queueMessage('Hello'); // will appear after 1 sec
  mqc.queueMessage('World'); // will appear after 2 sec

  // stop the process after 3 seconds
  new Timer(new Duration(seconds: 3), ()=> mqc.queueMessage('stop') );

  // this will not be processed
  new Timer(new Duration(seconds: 4), ()=> mqc.queueMessage('will not be processed') );

  // Loop waiting for processed values
  await for (var value in s) {
    if (value['OK'] == ' Processed msg : stop') break; // stop our loop if 'stop' is sent
    print(value['OK']); // Otherwise print the value

  }

}

Changelog

0.1.0

  • Initial version, created by Serge Besnard

example/async_message_queue_controller_example.dart

import 'package:async_message_queue_controller/async_message_queue_controller.dart';
import "dart:async";

/// The callback used by the controller to "process" a message/payload
/// Here the payload is a simple string, an simulates a heavy process
/// lasting 1 second.
/// returns a Map
Future<Map<String,String>> process(String msg){
  return new Future.delayed(const Duration(seconds: 1), () => {'OK':' Processed msg : $msg'});
}


/// Initializes a simple string message controller
void main() async {

  var mqc = new AsyncMessageQueueController<String, Map<String,String>>(process);


  Stream<Map<String, String>> s = mqc.start();

  mqc.queueMessage('Hello'); // will appear after 1 sec
  mqc.queueMessage('World'); // will appear after 2 sec

  // stop the process after 3 seconds
  new Timer(new Duration(seconds: 3), ()=> mqc.queueMessage('stop') );

  // will not be processed
  new Timer(new Duration(seconds: 4), ()=> mqc.queueMessage('will not be processed') );

  // Loop waiting for processed values
  await for (var value in s) {
    if (value['OK'] == ' Processed msg : stop') break;
    print(value['OK']);

  }
  mqc.stop();

}

Use this package as a library

1. Depend on it

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


dependencies:
  async_message_queue_controller: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:async_message_queue_controller/async_message_queue_controller.dart';
  
Version Uploaded Documentation Archive
0.1.1 Mar 2, 2018 Go to the documentation of async_message_queue_controller 0.1.1 Download async_message_queue_controller 0.1.1 archive
0.1.0 Mar 2, 2018 Go to the documentation of async_message_queue_controller 0.1.0 Download async_message_queue_controller 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:async_message_queue_controller/async_message_queue_controller.dart.

Health suggestions

Format lib/async_message_queue_controller.dart.

Run dartfmt to format lib/async_message_queue_controller.dart.

Format lib/src/async_message_queue_controller_base.dart.

Run dartfmt to format lib/src/async_message_queue_controller_base.dart.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
Dev dependencies
test ^0.12.0