OLD | NEW |
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.byte_stream; | 5 library channel.byte_stream; |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 .transform(new NotificationConverter()) | 44 .transform(new NotificationConverter()) |
45 .asBroadcastStream(); | 45 .asBroadcastStream(); |
46 } | 46 } |
47 | 47 |
48 @override | 48 @override |
49 Future close() { | 49 Future close() { |
50 return output.close(); | 50 return output.close(); |
51 } | 51 } |
52 | 52 |
53 @override | 53 @override |
54 Future<Response> sendRequest(Request request) { | 54 Future<Response> sendRequest(Request request) async { |
55 String id = request.id; | 55 String id = request.id; |
56 output.write(JSON.encode(request.toJson()) + '\n'); | 56 output.write(JSON.encode(request.toJson()) + '\n'); |
57 return responseStream.firstWhere((Response response) => response.id == id); | 57 return await responseStream |
| 58 .firstWhere((Response response) => response.id == id); |
58 } | 59 } |
59 } | 60 } |
60 | 61 |
61 /** | 62 /** |
62 * Instances of the class [ByteStreamServerChannel] implement a | 63 * Instances of the class [ByteStreamServerChannel] implement a |
63 * [ServerCommunicationChannel] that uses a stream and a sink (typically, | 64 * [ServerCommunicationChannel] that uses a stream and a sink (typically, |
64 * standard input and standard output) to communicate with clients. | 65 * standard input and standard output) to communicate with clients. |
65 */ | 66 */ |
66 class ByteStreamServerChannel implements ServerCommunicationChannel { | 67 class ByteStreamServerChannel implements ServerCommunicationChannel { |
67 final Stream _input; | 68 final Stream _input; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // structure as a request. | 164 // structure as a request. |
164 Request request = new Request.fromString(data); | 165 Request request = new Request.fromString(data); |
165 if (request == null) { | 166 if (request == null) { |
166 sendResponse(new Response.invalidRequestFormat()); | 167 sendResponse(new Response.invalidRequestFormat()); |
167 return; | 168 return; |
168 } | 169 } |
169 onRequest(request); | 170 onRequest(request); |
170 }); | 171 }); |
171 } | 172 } |
172 } | 173 } |
OLD | NEW |