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 // TODO(justinfagnani): use Timer when it works in isolates in dart2js | 78 new Timer(new Duration(milliseconds: millis), () { |
79 // see: http://dartbug.com/4997 | |
80 window.setTimeout(() { | |
81 replyTo.send('this is a reply from isolate "${isolateName}"', null); | 79 replyTo.send('this is a reply from isolate "${isolateName}"', null); |
82 }, millis); | 80 }); |
83 } | 81 } |
84 } | 82 } |
85 | 83 |
86 port.receive((message, SendPort replyTo) { | 84 port.receive((message, SendPort replyTo) { |
87 switch(message['id']) { | 85 switch(message['id']) { |
88 case MessageId.INIT: | 86 case MessageId.INIT: |
89 init(message['args'][0], message['args'][1]); | 87 init(message['args'][0], message['args'][1]); |
90 break; | 88 break; |
91 case MessageId.GREETING: | 89 case MessageId.GREETING: |
92 greeting(message['args'][0], replyTo); | 90 greeting(message['args'][0], replyTo); |
(...skipping 26 matching lines...) Expand all Loading... |
119 ports[isolateName].call(message).then((var msg) { | 117 ports[isolateName].call(message).then((var msg) { |
120 replyElement.text = msg; | 118 replyElement.text = msg; |
121 }); | 119 }); |
122 }); | 120 }); |
123 } | 121 } |
124 | 122 |
125 port.receive((var message, SendPort replyTo) { | 123 port.receive((var message, SendPort replyTo) { |
126 replyElement.text = message; | 124 replyElement.text = message; |
127 }); | 125 }); |
128 } | 126 } |
OLD | NEW |