Using isolates in the Dart VM
Dart code runs in a single thread, in what is called a single process or isolate. In the standalone Dart VM, all code starts from main()
and is executed in the so-called root
isolate. To make an app more responsive or to increase its performance, you can assign parts of the code to other isolates. Moreover, because there are no shared resources between isolates, isolating third-party code increases the application's overall security. A Dart server app or command-line app can run part of its code concurrently by creating multiple isolates. If the app runs on a machine with more than one core or processor, it means these isolates can run truly in parallel. When the root isolate terminates the Dart VM exits and, with it, all isolates that are still running. Dart web apps currently can't create additional isolates, but they can create workers by adding instances of the dart:html Worker
class, thereby adding JavaScript Web workers to the web app. In this recipe,...