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

Side by Side Diff: pkg/analysis_server/lib/src/channel.dart

Issue 235953019: Exit stdio-based analysis server when stdin closed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/http_server.dart ('k') | pkg/analysis_server/lib/stdio_server.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 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 channel; 5 library channel;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 /** 172 /**
173 * Instances of the class [ByteStreamServerChannel] implement a 173 * Instances of the class [ByteStreamServerChannel] implement a
174 * [ClientCommunicationChannel] that uses a stream and a sink (typically, 174 * [ClientCommunicationChannel] that uses a stream and a sink (typically,
175 * standard input and standard output) to communicate with servers. 175 * standard input and standard output) to communicate with servers.
176 */ 176 */
177 class ByteStreamServerChannel implements ServerCommunicationChannel { 177 class ByteStreamServerChannel implements ServerCommunicationChannel {
178 final Stream input; 178 final Stream input;
179 final IOSink output; 179 final IOSink output;
180 180
181 /**
182 * Completer that will be signalled when the input stream is closed.
183 */
184 final Completer _closed = new Completer();
185
181 ByteStreamServerChannel(this.input, this.output); 186 ByteStreamServerChannel(this.input, this.output);
182 187
188 /**
189 * Future that will be completed when the input stream is closed.
190 */
191 Future get closed {
192 return _closed.future;
193 }
194
183 @override 195 @override
184 void listen(void onRequest(Request request), {Function onError, void 196 void listen(void onRequest(Request request), {Function onError, void
185 onDone()}) { 197 onDone()}) {
186 input.transform((new Utf8Codec()).decoder).transform(new LineSplitter() 198 input.transform((new Utf8Codec()).decoder).transform(new LineSplitter()
187 ).listen((String data) => _readRequest(data, onRequest), onError: onErro r, 199 ).listen((String data) => _readRequest(data, onRequest), onError: onErro r,
188 onDone: onDone); 200 onDone: () {
201 _closed.complete();
Brian Wilkerson 2014/04/16 17:23:43 Out of curiosity, why not just add this line to on
Paul Berry 2014/04/16 17:28:40 Because onDone() isn't a local function. It's pas
202 onDone();
203 });
189 } 204 }
190 205
191 @override 206 @override
192 void sendNotification(Notification notification) { 207 void sendNotification(Notification notification) {
193 output.writeln(JSON.encode(notification.toJson())); 208 output.writeln(JSON.encode(notification.toJson()));
194 } 209 }
195 210
196 @override 211 @override
197 void sendResponse(Response response) { 212 void sendResponse(Response response) {
198 output.writeln(JSON.encode(response.toJson())); 213 output.writeln(JSON.encode(response.toJson()));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 302 }
288 } 303 }
289 } 304 }
290 305
291 @override 306 @override
292 void close() { 307 void close() {
293 closed = true; 308 closed = true;
294 sink.close(); 309 sink.close();
295 } 310 }
296 } 311 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/http_server.dart ('k') | pkg/analysis_server/lib/stdio_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698