Skip to content

Instantly share code, notes, and snippets.

@StrykerKKD
Created December 6, 2014 21:01
Show Gist options
  • Save StrykerKKD/286cf2d51e436a347608 to your computer and use it in GitHub Desktop.
Save StrykerKKD/286cf2d51e436a347608 to your computer and use it in GitHub Desktop.
Dart: Isolate example in a funny way
import 'dart:isolate';
//This is the worker
void worker(SendPort request) {
ReceivePort response = new ReceivePort();
request.send(response.sendPort);
response.listen((message){
print("Boss: $message");
request.send("....");
response.close();
});
}
//This is the boss
main() {
ReceivePort response = new ReceivePort();
SendPort request;
Isolate.spawn(worker, response.sendPort);
response.listen((message){
if(message is SendPort) {
request = message;
request.send("Ummmm Yeeeahh if you could get this TPS report done today. That'd be great.");
} else {
print("Worker: $message");
response.close();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment