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

Side by Side Diff: samples/total/src/TotalRunner.dart

Issue 9024008: Change the process API to be completely asynchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add binaries. Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/total/src/Dartc.dart ('k') | tests/standalone/src/ProcessBrokenPipe.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 #library("total:runner"); 6 #library("total:runner");
7 7
8 typedef void ExitCallback(int status, String exitString); 8 typedef void ExitCallback(int status, String exitString);
9 9
10 void main() { 10 void main() {
(...skipping 21 matching lines...) Expand all
32 String _serverMain; 32 String _serverMain;
33 33
34 // TODO: Release or Debug? We should be able to find automatically 34 // TODO: Release or Debug? We should be able to find automatically
35 static final DART_EXEC_PATH = '../../../out/Release_ia32/dart'; 35 static final DART_EXEC_PATH = '../../../out/Release_ia32/dart';
36 static final CR = 0x0d; 36 static final CR = 0x0d;
37 static final LF = 0x0a; 37 static final LF = 0x0a;
38 38
39 ServerRunner(String this._serverMain); 39 ServerRunner(String this._serverMain);
40 40
41 void run(ExitCallback exitCallback) { 41 void run(ExitCallback exitCallback) {
42 Process dart = new Process(DART_EXEC_PATH, [_serverMain]); 42 Process dart = new Process.start(DART_EXEC_PATH, [_serverMain]);
43 43
44 dart.exitHandler = (int status) { 44 dart.exitHandler = (int status) {
45 dart.close(); 45 dart.close();
46 exitCallback(status, this); 46 exitCallback(status, this);
47 }; 47 };
48
49 dart.start();
50 48
51 dart.stdout.dataHandler = () => readMore(dart.stdout, new StringBuffer()); 49 dart.stdout.dataHandler = () => readMore(dart.stdout, new StringBuffer());
52 dart.stderr.dataHandler = () => readMore(dart.stderr, new StringBuffer()); 50 dart.stderr.dataHandler = () => readMore(dart.stderr, new StringBuffer());
53 } 51 }
54 52
55 void readMore(InputStream i, StringBuffer readSoFar) { 53 void readMore(InputStream i, StringBuffer readSoFar) {
56 while(i.available() != 0) { 54 while(i.available() != 0) {
57 processBuffer(i.read(), readSoFar); 55 processBuffer(i.read(), readSoFar);
58 } 56 }
59 } 57 }
60 58
61 void processBuffer(List<int> buf, StringBuffer readSoFar) { 59 void processBuffer(List<int> buf, StringBuffer readSoFar) {
62 buf.forEach((int i) { 60 buf.forEach((int i) {
63 if (i != CR && i != LF) { 61 if (i != CR && i != LF) {
64 readSoFar.add(new String.fromCharCodes([i])); 62 readSoFar.add(new String.fromCharCodes([i]));
65 } else { 63 } else {
66 String line = readSoFar.toString(); 64 String line = readSoFar.toString();
67 readSoFar.clear(); 65 readSoFar.clear();
68 if (line.length != 0) { 66 if (line.length != 0) {
69 print(line); 67 print(line);
70 } 68 }
71 } 69 }
72 }); 70 });
73 } 71 }
74 } 72 }
OLDNEW
« no previous file with comments | « samples/total/src/Dartc.dart ('k') | tests/standalone/src/ProcessBrokenPipe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698