| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 element.on.click.add((Event e) { | 65 element.on.click.add((Event e) { |
| 66 replyElement.text = "waiting for reply..."; | 66 replyElement.text = "waiting for reply..."; |
| 67 | 67 |
| 68 // get the last letter on the button (assuming the button text is, for | 68 // get the last letter on the button (assuming the button text is, for |
| 69 // example, "send message to A". | 69 // example, "send message to A". |
| 70 String buttonText = e.currentTarget.dynamic.attributes["value"]; | 70 String buttonText = e.currentTarget.dynamic.attributes["value"]; |
| 71 String isolateName = buttonText[buttonText.length - 1]; | 71 String isolateName = buttonText[buttonText.length - 1]; |
| 72 String greeting = document.query("#greetingText").dynamic.value; | 72 String greeting = document.query("#greetingText").dynamic.value; |
| 73 var message = { "id": MessageId.GREETING, "args" : [ greeting ] }; | 73 var message = { "id": MessageId.GREETING, "args" : [ greeting ] }; |
| 74 ports[isolateName].call(message).receive( | 74 ports[isolateName].call(message).receive( |
| 75 (var message, SendPort replyTo) { | 75 (var msg, SendPort replyTo) { |
| 76 replyElement.text = message; | 76 replyElement.text = msg; |
| 77 }); | 77 }); |
| 78 }); | 78 }); |
| 79 } | 79 } |
| 80 | 80 |
| 81 chirpPort.receive((var message, SendPort replyTo) { | 81 chirpPort.receive((var message, SendPort replyTo) { |
| 82 replyElement.text = message; | 82 replyElement.text = message; |
| 83 }); | 83 }); |
| 84 } | 84 } |
| 85 | 85 |
| 86 static void main() { | 86 static void main() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 114 case MessageId.INIT: | 114 case MessageId.INIT: |
| 115 init(message["args"][0], message["args"][1]); | 115 init(message["args"][0], message["args"][1]); |
| 116 break; | 116 break; |
| 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 = new Element.tag("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 |