Skip to content

Instantly share code, notes, and snippets.

@adam-singer
Created March 14, 2012 03:48
Show Gist options
  • Save adam-singer/2033887 to your computer and use it in GitHub Desktop.
Save adam-singer/2033887 to your computer and use it in GitHub Desktop.
Hello world using new dart:isolate
#!/usr/bin/env dart
#import('dart:isolate', prefix:'isolate');
isolateCode() {
isolate.port.receive((msg, reply) => reply.send("re: $msg"));
}
void main() {
isolate.SendPort sendPort = isolate.spawnFunction(isolateCode);
sendPort.call("Hello World").then(print);
}
@adam-singer
Copy link
Author

Make this script executable chmod +x ./HelloIsolate.dart and ensure dart is in your $PATH.

@sethladd
Copy link

Thanks Adam. Note, you don't need the prefix with the #import. Curious, do you prefer this style or was there a different motivation?

@adam-singer
Copy link
Author

It was copied from the post http://goo.gl/p3eAf , kept it in only cause it explicitly shows what is being used from the dart:isolate module. Using it going forward I probably wouldn't prefix. Reasons I might would be naming conflicts or displaying explicit intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment