operation_queue 0.5.3

SDKflutter
Platformandroidioswindowslinuxmacos

An easy multi task utility that can control the number of concurrency.

Features

An easy multi task utility that can control the number of concurrency.

Getting started

Add the dependency in pubspec.yaml:

dependencies:
  ...
  operation_queue: ^0.5.1

Usage

  /// 3 tasks can run concurrently.
  /// Each task takes an integer as input and generates integers as output.
  var opeartionQueue = OperationQueue<int, int>(
      concurrency: 3,
      task: (data) async* {
        final startDate = DateTime.now();
        for (var i = 0; i < data; i++) {
          await Future.delayed(const Duration(milliseconds: 100));

          // produce output
          yield data*10;
        }
      });

  void _heavyWork() async {

    opeartionQueue.listen((event) {
      print('output: $event.');
    });

    for (var count in [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12]) {
      opeartionQueue.add(count);
    }
  }