Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: samples/isolate_html/isolate_sample.dart

Issue 12887009: Support asynchronuous spawnDomFunction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | tools/dom/src/native_DOMPublic.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/isolate_html/isolate_sample.dart
diff --git a/samples/isolate_html/isolate_sample.dart b/samples/isolate_html/isolate_sample.dart
index 4f239a8811329435a40c7afd7fbf8ffdb846e733..81437ef8bab8b5bb9c275859a8e45bc3e20aaea2 100644
--- a/samples/isolate_html/isolate_sample.dart
+++ b/samples/isolate_html/isolate_sample.dart
@@ -27,14 +27,15 @@ class MessageId {
* them names in this app so we can show which isolate is doing
* what.
*/
-SendPort createIsolate(String name) {
- var sendPort = spawnDomFunction(isolateMain);
- var message = {
- 'id' : MessageId.INIT,
- 'args' : [name, port.toSendPort()]
- };
- sendPort.send(message, null);
- return sendPort;
+Future<SendPort> createIsolate(String name) {
+ return spawnDomFunction(isolateMain).transform((sendPort) {
vsm 2013/03/26 19:13:37 transform -> then?
Anton Muhin 2013/03/26 19:15:37 I have to return a future as well, hence I used tr
vsm 2013/03/26 19:21:39 Future.then returns a Future. I don't see transfo
Anton Muhin 2013/03/27 08:41:46 You're absolutely right, sorry, got confused. On
+ var message = {
+ 'id' : MessageId.INIT,
+ 'args' : [name, port.toSendPort()]
+ };
+ sendPort.send(message, null);
+ return sendPort;
+ });
}
// TODO(mattsh) get this off the System object once it's available
@@ -103,24 +104,28 @@ main() {
var replyElement = query('.isolateMain .replyText');
- ports['A'] = createIsolate('A');
- ports['B'] = createIsolate('B');
-
- for (var element in queryAll('.sendButton')) {
- element.onClick.listen((Event e) {
- replyElement.text = 'waiting for reply...';
+ createIsolate('A').then((sendPortA) {
+ ports['A'] = sendPortA;
+ createIsolate('B').then((sendPortB) {
+ ports['B'] = sendPortB;
+
+ for (var element in queryAll('.sendButton')) {
+ element.onClick.listen((Event e) {
+ replyElement.text = 'waiting for reply...';
+
+ var isolateName =
+ (e.currentTarget as Element).attributes['data-isolate-name'];
+ var greeting = query('input#greetingText').value;
+ var message = {'id': MessageId.GREETING, 'args': [greeting]};
+ ports[isolateName].call(message).then((var msg) {
+ replyElement.text = msg;
+ });
+ });
+ }
- var isolateName =
- (e.currentTarget as Element).attributes['data-isolate-name'];
- var greeting = query('input#greetingText').value;
- var message = {'id': MessageId.GREETING, 'args': [greeting]};
- ports[isolateName].call(message).then((var msg) {
- replyElement.text = msg;
+ port.receive((var message, SendPort replyTo) {
+ replyElement.text = message;
});
});
- }
-
- port.receive((var message, SendPort replyTo) {
- replyElement.text = message;
});
}
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | tools/dom/src/native_DOMPublic.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698