O'Reilly logo

Dart: Scalable Application Development by Ivo Balbaert, Sergey Akopkokhyants, Davy Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using isolates in web apps

In this recipe, you will learn how to use isolates in a web application in the project using_web_isolates. This example runs in the Dart VM embedded in a browser as well as compiled to JavaScript. In the latter case, it uses HTML5 Web workers, which runs in the background independently of other scripts without affecting the performance of the page.

How to do it...

The main isolate in using_web_isolates.dart runs the following code:

import'dart:isolate';
import'dart:html';
import'dart:async';

main() {
  Element output = querySelector('output');
  SendPortsendPort;
  ReceivePortreceivePort = new ReceivePort();
  receivePort.listen((msg) { if (sendPort == null) { sendPort = msg; } else { output.text += 'Received from isolate: $msg\n'; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required