Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the Worker Task framework


The isolate library only gives us the low-level, basic building blocks, so working with isolates in a realistic application environment can be challenging. Specifically for this purpose, the worker concurrent task executor framework was developed by Diego Rocha, available from pub package manager. It was made to abstract all the isolate managing and message passing and make concurrency in Dart as easy as possible. Worker also contains built-in error handling, so you needn't worry about that either. This recipe will show you how to use this framework so that you can concentrate on higher-level application details.

How to do it...

In the project using_worker, you can find a number of programs (using_worker1 through using_worker4) illustrating the use of this framework. The script using_worker.dart illustrates the main steps, namely creating a task, creating a worker, give a task to the worker, and process the results:

import'package:worker/worker.dart';

Worker...