Skip to content

Instantly share code, notes, and snippets.

@fujidig
Created October 11, 2011 14:38
Show Gist options
  • Select an option

  • Save fujidig/1278255 to your computer and use it in GitHub Desktop.

Select an option

Save fujidig/1278255 to your computer and use it in GitHub Desktop.
DartのIsolateで重い処理をさせてみる
#import('dart:dom');
main() {
window.addEventListener('DOMContentLoaded', (e) => ready(), false);
}
ready() {
ReceivePort local = new ReceivePort();
SendPort reply = local.toSendPort();
local.receive((message, SendPort replyTo) {
if (message == "おわります") {
local.close();
}
document.querySelector("#out").textContent = message;
});
new MyIsolate().spawn().then((port) {
port.send("開始しろ", reply);
});
}
class MyIsolate extends Isolate {
MyIsolate() : super.heavy() {}
void main() {
this.port.receive((message, SendPort replyTo) {
for (var i = 0; i < 100000; i ++) {
replyTo.send("おっすおっす!! "+i);
}
replyTo.send("おわります");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment