| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * These are the messages we are going to send to the isolates | 6 * These are the messages we are going to send to the isolates |
| 7 * that we create. | 7 * that we create. |
| 8 */ | 8 */ |
| 9 class MessageId { | 9 class MessageId { |
| 10 static final INIT = "init"; | 10 static final INIT = "init"; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 case MessageId.GREETING: | 117 case MessageId.GREETING: |
| 118 greeting(message["args"][0], replyTo); | 118 greeting(message["args"][0], replyTo); |
| 119 break; | 119 break; |
| 120 } | 120 } |
| 121 }); | 121 }); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void init(String isolateName, SendPort chirpPort) { | 124 void init(String isolateName, SendPort chirpPort) { |
| 125 this.isolateName = isolateName; | 125 this.isolateName = isolateName; |
| 126 this.chirpPort = chirpPort; | 126 this.chirpPort = chirpPort; |
| 127 div = document.createElement("div"); | 127 div = new Element.tag("div"); |
| 128 div.classes = ["isolate", "isolate${isolateName}"]; | 128 div.classes = ["isolate", "isolate${isolateName}"]; |
| 129 div.innerHTML = document.query("#isolateTemplate"). | 129 div.innerHTML = document.query("#isolateTemplate"). |
| 130 firstElementChild.dynamic.innerHTML; | 130 firstElementChild.dynamic.innerHTML; |
| 131 div.query(".isolateName").text = isolateName; | 131 div.query(".isolateName").text = isolateName; |
| 132 document.query("#isolateParent").nodes.add(div); | 132 document.query("#isolateParent").nodes.add(div); |
| 133 div.query(".chirpButton").on.click.add( | 133 div.query(".chirpButton").on.click.add( |
| 134 void _(Event) { chirpPort.call( | 134 void _(Event) { chirpPort.call( |
| 135 "this is a chirp message from isolate " + isolateName); | 135 "this is a chirp message from isolate " + isolateName); |
| 136 }, false); | 136 }, false); |
| 137 } | 137 } |
| 138 | 138 |
| 139 /** | 139 /** |
| 140 * Display the message we received, and send back a simple reply (unless | 140 * Display the message we received, and send back a simple reply (unless |
| 141 * the user has unchecked the reply checkbox). | 141 * the user has unchecked the reply checkbox). |
| 142 */ | 142 */ |
| 143 void greeting(String message, SendPort replyTo) { | 143 void greeting(String message, SendPort replyTo) { |
| 144 div.query(".messageBox").dynamic.innerHTML = | 144 div.query(".messageBox").dynamic.innerHTML = |
| 145 "received message: <span class='messageText'>'${message}'</span>"; | 145 "received message: <span class='messageText'>'${message}'</span>"; |
| 146 if (div.query(".replyCheckbox").dynamic.checked) { | 146 if (div.query(".replyCheckbox").dynamic.checked) { |
| 147 InputElement element = div.query(".delayTextbox"); | 147 InputElement element = div.query(".delayTextbox"); |
| 148 int millis = Math.parseInt(element.value); | 148 int millis = Math.parseInt(element.value); |
| 149 window.setTimeout(() { | 149 window.setTimeout(() { |
| 150 replyTo.send("this is a reply from isolate '${isolateName}'", null); | 150 replyTo.send("this is a reply from isolate '${isolateName}'", null); |
| 151 }, millis); | 151 }, millis); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 } | 154 } |
| OLD | NEW |