executor 2.1.2

Async task executor for Dart #

Executes async tasks with a configurable maximum concurrency and rate.

Usage #

A simple usage example:

import 'dart:async';

import 'package:executor/executor.dart';

Future main() async {
  Executor executor = new Executor(concurrency: 10);
  // only 10 of them will be running at a time
  for (int i = 0; i < 20; i++) {
     executor.scheduleTask(() async {
       // await longDatabaseTask()
       // await anotherProcessing()
     });
  }
}

Changelog #

2.1.2 #

  • Using package:stack_trace to chain async stacktraces when task fails.

2.1.1 #

  • Improved design on loop and scheduling, preserving caller stacktrace with full details.

2.1.0 #

  • Removed Timers to schedule tasks, using a simple loop instead.
  • Better distribution for rate-limited executions.

2.0.0 #

  • Supporting Dart 2 only.

1.0.1 #

  • Dart2 compatibility with package:dart2_constant.

1.0.0 #

Breaking changes

  • Removed deprecated member limit.
  • Renamed ExecutorTask -> AsyncTask, return value to FutureOr.
  • Renamed Rate.limit -> Rate.maximum.

New features

  • Added Executor.onChange. Clients can use this to monitor the current scheduledCount and queue more tasks to ensure Executor is running on full capacity.

Housekeeping

  • Added example.
  • Added a few tests.

0.1.2 #

  • Expose internal stats: runningCount, waitingCount, scheduledCount.
  • Enable sync-points with join(), which allows to track the completion of the currently running (and optionally the waiting) tasks.

0.1.1 #

  • Fix missing heartbeat check on Executor.close(), without it the Future might not have completed.

0.1 #

  • start-rate limit support
  • renamed limit to concurrency (leaving old field, marked deprecated)

example/example.dart

// Copyright (c) 2017, Agilord. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:executor/executor.dart';

Future main() async {
  Executor executor = new Executor(concurrency: 10);
  // only 10 of them will be running at a time
  for (int i = 0; i < 20; i++) {
    executor.scheduleTask(() async {
      // await longDatabaseTask()
      // await anotherProcessing()
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  executor: ^2.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:executor/executor.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
54
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/executor.dart. (-1 points)

Analysis of lib/executor.dart reported 2 hints:

line 66 col 20: Use = to separate a named parameter from its default value.

line 92 col 32: Use = to separate a named parameter from its default value.

Fix lib/src/executor_impl.dart. (-0.50 points)

Analysis of lib/src/executor_impl.dart reported 1 hint:

line 120 col 32: Use = to separate a named parameter from its default value.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
stack_trace >=1.9.0 <2.0.0 1.9.3
Transitive dependencies
path 1.6.2
Dev dependencies
test ^1.3.0

Admin