Isolates

As the name implies, Dart isolates are used to isolate long-running functions from the main thread of execution. Dart isolates do not share any memory so they rely on message passing for communication, making for very elegant concurrent programming solutions. Message passing is achieved through port objects and uses Futures to signal when isolates and messages are ready.

Isolates are imported from the dart:isolate library. The easiest way to use them is with the Isolate.spawnUri() method.

isolates/test/isolates.dart
 
import​ ​'dart:isolate'​;
 
var​ res = ​new​ ReceivePort();
 
var​ sender = Isolate.spawnUri(
 
Uri.parse(​'isolates/main.dart'​),
 
[​'2014'​],
 
res.sendPort
 
);
 
sender.
 
then((_)=> res.first).
 
then((message) {

Get Dart 1 for Everyone now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.