worker_manager 2.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

Executor is instrument to run any functions inside separate dart isolate. This is useful if you want to avoid lags and freezes in UI isolate(main). If you parse big json data or calculating math it can make your app laggy. To solve this problem, make sure that you functions, which working with Executor is static or defined as global (just in a dart file, not inside a class).

First step: Executor - is a Singleton, you can call Executor everywhere you want, it will not produce any instance except first one.

Second step: You can set isolatePool size for Executor and warm up isolates. Write this code inside main function (make sure that you main is async):

 await Executor(threadPoolSize: 2).warmUp();

Third step: To run code inside isolate you should create a Task

final task = Task<return type>(function: yourFunction,
 bundle: one parameter for your function, it can be empty
 timeout: Duration( time for calculation) - optional parameter

Fourth step: Call Executor.addTask(you task). it will return Stream with result. Here is example:

Executor().addTask<parameter type, return type>(
    task: Task(function: yourFunction, bundle: parameter,
     timeout: Duration(seconds: 25))).listen((data) {
                handle with you result
              }).onError((error) {
                handle error

Bonus: you can stop task every time you want. Removing task will produce nothing and you will not get any data inside listen method.

final task1 = Task(function: fibonacci, bundle: 88);
Executor.addTask(task: task1).listen((data){
        nothing here
Executor().removeTask(task: task1);

Optional: you can end work with Executor().


[2.0.5] - 10 nov 2019 21.36

*0.1.0 correct timeouts (canceling coming soon)

*0.2.1 added canceling functionality

*0.2.3 added examples and readme

*0.4.1 changed readme

*0.7.8 code clean up

*0.9.1 added 1 thread constructor for fake fifo and threadPoolSize setter

*0.9.8 added cash

*1.0.1 fixed timeout

*1.2.0 resolved deleting task bug

*1.2.8 fixed bugs with removing same task twice

*2.0.0 removed ports hell

*2.0.1 removed ghost connection

*2.0.4 clean up

*2.0.5 fifo adding



// Copyright Daniil Surnin. All rights reserved.
// Use of this source code is governed by a Apache license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:worker_manager/worker_manager.dart';

void main() async {
  /* this is not necessary, this code will spawn
   before your awesome widgets will build,
   to avoid micro freezes
   if you don't want to spawn free of calculation isolates,
   just don't write this code :

await WorkerManager().initManager(); runApp(MyApp()); }

class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( showPerformanceOverlay: true, home: MyHomePage(), ); } }

class MyHomePage extends StatefulWidget { MyHomePage({Key key}) : super(key: key); @override _MyHomePageState createState() => _MyHomePageState(); }

class _MyHomePageState extends State

/* creating task for workerManager with global function and Bundle class for your function. bundle and timeout is optional parameters. */ final task = Task(function: fib, bundle: 40, timeout: Duration(days: 78));

/*remember, that you global function must have only one parameter, like int, String or your bundle class . For example: Class Bundle { final int age; final String name; Bundle(this.age,; } optional parameters is ok, just be ready to avoid NPE */ @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Container( height: 350, width: 200, color: Colors.cyan, child: Column( children:

@override void dispose() { // Good case when you want to end your hard calculations in dispose method workerManager.killTask(task: task); super.dispose(); } }

int fib(int n) { if (n < 2) { return n; } return fib(n - 2) + fib(n - 1); }


Use this package as a library

1. Depend on it

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

  worker_manager: ^2.0.6

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support 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:worker_manager/worker_manager.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 Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

55 out of 55 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.

Format lib/executor.dart.

Run flutter format to format lib/executor.dart.

Format lib/isolate.dart.

Run flutter format to format lib/isolate.dart.

Format lib/scheduler.dart.

Run flutter format to format lib/scheduler.dart.

Format lib/worker_manager.dart.

Run flutter format to format lib/worker_manager.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
async ^2.3.0 2.4.0
flutter 0.0.0
uuid ^2.0.2 2.0.2
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies