worker 0.5.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 16

Worker #

Build Status

An easy to use utility to perform tasks concurrently.

By performing blocking CPU intensive tasks concurrently, you free your main isolate to do other stuff while you take advantage of the CPU capabilities.

Usage #

To use this library, create a new Worker that will handle the isolates for you, encapsulate your task in class that implements the Task interface and pass it to the Worker to execute it:

void main () {
	Worker worker = new Worker();
	Task task = new AckermannTask(1, 2);
	worker.handle(task).then((result) => print(result));
}

class AckermannTask implements Task {
  int x, y;

  AckermannTask (this.x, this.y);

  int execute () {
    return ackermann(x, y);
  }

  int ackermann (int m, int n) {
    if (m == 0)
      return n+1;
    else if (m > 0 && n == 0)
      return ackermann(m-1, 1);
    else
      return ackermann(m-1, ackermann(m, n-1));
  }
}

You can also define how many tasks a worker can execute concurrently and if the isolates should be spawned lazily:

Worker worker = new Worker(poolSize: 4, spawnLazily: false);

If you want to manage the isolates and SendPorts yourself but still use Tasks, WorkerIsolate comes to the rescue:

WorkerIsolate isolate = new WorkerIsolate();
isolate.performTask(new AckermannTask(1, 2))
		.then(doSomethingAwesome);

Tips #

  • A Task may return a Future. The Worker will wait until this Future is completed and will return its result.
  • If you have to perform many iterations of an operation, you can batch it into tasks and run them concurrently.
  • Running tasks in other isolates involves copying the task object to the other isolate. Keep your task thin.
  • Always use benchmarks to identify if Worker is really helping and if the amount of isolates is ideal.

Changelog #

0.5.0 #

Workers and WorkerIsolates now can wait until all tasks have been completed before closing. ([#10] (https://github.com/Dreckr/Worker/issues/10))

0.4.0 #

Streams of events have been added, giving better monitoring capabilities. (#11)

0.3.11 #

Loosen stack_trace min version dependency. (#12)

0.3.10 #

Support tasks that do not return. (#8)

0.3.9 #

Proper error handling with stackTrace support. (#7)

0.3.8 #

WorkerIsolate factory. (#6)

0.3.7 #

Bug fix.

0.3.6 #

Minor bug fix.

0.3.5 #

Bug fix.

0.3.4 #

Improved isolate selection and load distribution.

0.3.3 #

Major bug fix.

0.3.2 #

Major bug fix.

0.3.1 #

Bug fixes.

0.3.0 #

Work with new Isolates API.

0.2.2 #

Minor bug fix.

0.2.1 #

Bug fixes.

0.2.0 #

Major rewrite:

  • Isolates now may handle more than one Task at the time.
  • Creation of the WorkerIsolate to abstract comunication with isolates.
  • 'execute' method from Worker renamed to 'handle'.
  • Workers and WorkerIsolates may be closed.
  • Errors are now handled properly.

Use this package as a library

1. Depend on it

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


dependencies:
  worker: ^0.5.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:worker/worker.dart';
  
Version Uploaded Documentation Archive
0.5.0 Jul 27, 2014 Go to the documentation of worker 0.5.0 Download worker 0.5.0 archive
0.4.0 Jul 13, 2014 Go to the documentation of worker 0.4.0 Download worker 0.4.0 archive
0.3.11 Jun 20, 2014 Go to the documentation of worker 0.3.11 Download worker 0.3.11 archive
0.3.10 Jun 15, 2014 Go to the documentation of worker 0.3.10 Download worker 0.3.10 archive
0.3.9 Jun 14, 2014 Go to the documentation of worker 0.3.9 Download worker 0.3.9 archive
0.3.8 Jun 7, 2014 Go to the documentation of worker 0.3.8 Download worker 0.3.8 archive
0.3.7 Feb 15, 2014 Go to the documentation of worker 0.3.7 Download worker 0.3.7 archive
0.3.6 Feb 13, 2014 Go to the documentation of worker 0.3.6 Download worker 0.3.6 archive
0.3.5 Feb 12, 2014 Go to the documentation of worker 0.3.5 Download worker 0.3.5 archive
0.3.4 Feb 12, 2014 Go to the documentation of worker 0.3.4 Download worker 0.3.4 archive

All 18 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
16
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0