I recently started with Dart (www.dartlang.org) and really like it so far. A very promising feature are isolates, but I am not sure on how to start.
The documentation I found so far is from before a breaking change (BREAKING CHANGE: dart:isolate) in October 2013. The information in this "Breaking change" email is quite complicated and it looks like the new api is more complicated than the old.
I've got some questions:
I tried this example and it works https://gist.github.com/olostan/7883315
import "dart:isolate";
void main() {
print("Starting");
var sPort = new ReceivePort();
SendPort rPort;
sPort.listen((msg) {
if (msg is SendPort) {
print("Host got port. sending back");
rPort = msg;
rPort.send("Hello!");
}
else print("Host got $msg");
rPort.send(null);
sPort.close();
});
Isolate.spawn(test,sPort.sendPort);
}
void test(sender) {
var rPort = new ReceivePort();
sender.send(rPort.sendPort);
rPort.listen((msg){
print("Worker got $msg");
if (msg!=null)
sender.send("I am worker");
else rPort.close();
});
}
Isolates seem not to be used too much yet so there may still be some bugs.
The latest problems I remember reading about was debugging code running in isolates. I don't know if this is solved yet.
It also depends if you want to use isolates on the server or in the browser.
AFAIK it's more stable in the VM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With