| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library isolate_sample; | 5 library isolate_sample; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 9 | 9 |
| 10 /* | 10 /* |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 /** | 68 /** |
| 69 * Display the message we received, and send back a simple reply (unless | 69 * Display the message we received, and send back a simple reply (unless |
| 70 * the user has unchecked the reply checkbox). | 70 * the user has unchecked the reply checkbox). |
| 71 */ | 71 */ |
| 72 void greeting(String message, SendPort replyTo) { | 72 void greeting(String message, SendPort replyTo) { |
| 73 div.query('.messageBox').innerHtml = | 73 div.query('.messageBox').innerHtml = |
| 74 'received message: <span class="messageText">"${message}"</span>'; | 74 'received message: <span class="messageText">"${message}"</span>'; |
| 75 if (div.query('input.replyCheckbox').checked) { | 75 if (div.query('input.replyCheckbox').checked) { |
| 76 InputElement element = div.query('.delayTextbox'); | 76 InputElement element = div.query('.delayTextbox'); |
| 77 int millis = int.parse(element.value); | 77 int millis = int.parse(element.value); |
| 78 new Timer(new Duration(milliseconds: millis), () { | 78 // TODO(justinfagnani): use Timer when it works in isolates in dart2js |
| 79 // see: http://dartbug.com/4997 |
| 80 window.setTimeout(() { |
| 79 replyTo.send('this is a reply from isolate "${isolateName}"', null); | 81 replyTo.send('this is a reply from isolate "${isolateName}"', null); |
| 80 }); | 82 }, millis); |
| 81 } | 83 } |
| 82 } | 84 } |
| 83 | 85 |
| 84 port.receive((message, SendPort replyTo) { | 86 port.receive((message, SendPort replyTo) { |
| 85 switch(message['id']) { | 87 switch(message['id']) { |
| 86 case MessageId.INIT: | 88 case MessageId.INIT: |
| 87 init(message['args'][0], message['args'][1]); | 89 init(message['args'][0], message['args'][1]); |
| 88 break; | 90 break; |
| 89 case MessageId.GREETING: | 91 case MessageId.GREETING: |
| 90 greeting(message['args'][0], replyTo); | 92 greeting(message['args'][0], replyTo); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 117 ports[isolateName].call(message).then((var msg) { | 119 ports[isolateName].call(message).then((var msg) { |
| 118 replyElement.text = msg; | 120 replyElement.text = msg; |
| 119 }); | 121 }); |
| 120 }); | 122 }); |
| 121 } | 123 } |
| 122 | 124 |
| 123 port.receive((var message, SendPort replyTo) { | 125 port.receive((var message, SendPort replyTo) { |
| 124 replyElement.text = message; | 126 replyElement.text = message; |
| 125 }); | 127 }); |
| 126 } | 128 } |
| OLD | NEW |