Spawning isolates in Dart

Spawning new isolates in Dart is easy if you know how to do it:


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

void main() {
  Future isolate1 = Isolate.spawnUri(Uri.parse('isolate.dart'), [], null);
  Future isolate2 = Isolate.spawnUri(Uri.parse('isolate.dart'), [], null);

Future.wait only waits until the two isolates are spawned. If the main application stops running, the two spawned isolates will stop running as well. That’s why we need a while(true)-loop here.

The isolate itself looks like this:

library isolate;

void main() {

The two arguments after the URI are used for a list of arguments and an optional message. If you want to use this, just modify the main method of your isolate:

void main(args) {...}
void main(args, message) {...}

[Dart+Polymer] Styling Elements

Styling custom elements is sometimes tricky. In general the website styles do NOT apply to the custom element. There is a special attribute called „apply-author-styles“ that can be set to „true“ to apply your website’s styles to your custom element.

In general each custom element should have its  styles separated from the website so it can be reused easily. Let’s have a look at a simple example: