Created
October 11, 2011 14:38
-
-
Save fujidig/1278255 to your computer and use it in GitHub Desktop.
DartのIsolateで重い処理をさせてみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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