OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 /** | 7 /** |
8 * Helper class to wrap a [StreamConsumer<List<int>>] and provide | 8 * Helper class to wrap a [StreamConsumer<List<int>>] and provide |
9 * utility functions for writing to the StreamConsumer directly. The | 9 * utility functions for writing to the StreamConsumer directly. The |
10 * [IOSink] buffers the input given by all [StringSink] methods and will delay | 10 * [IOSink] buffers the input given by all [StringSink] methods and will delay |
(...skipping 28 matching lines...) Expand all Loading... |
39 * Writes an error to the consumer. | 39 * Writes an error to the consumer. |
40 */ | 40 */ |
41 void addError(error, [StackTrace stackTrace]); | 41 void addError(error, [StackTrace stackTrace]); |
42 | 42 |
43 /** | 43 /** |
44 * Adds all elements of the given [stream] to `this`. | 44 * Adds all elements of the given [stream] to `this`. |
45 */ | 45 */ |
46 Future addStream(Stream<List<int>> stream); | 46 Future addStream(Stream<List<int>> stream); |
47 | 47 |
48 /** | 48 /** |
| 49 * Returns a [Future] that completes once all buffered data is accepted by the |
| 50 * to underlying [StreamConsumer]. |
| 51 * |
| 52 * It's an error to call this method, while an [addStream] is incomplete. |
| 53 * |
| 54 * NOTE: This is not necessarily the same as the data being flushed by the |
| 55 * operating system. |
| 56 */ |
| 57 Future flush(); |
| 58 |
| 59 /** |
49 * Close the target. | 60 * Close the target. |
50 */ | 61 */ |
51 Future close(); | 62 Future close(); |
52 | 63 |
53 /** | 64 /** |
54 * Get a future that will complete when all synchronous have completed, or an | 65 * Get a future that will complete when all synchronous have completed, or an |
55 * error happened. This future is identical to the future returned from close. | 66 * error happened. This future is identical to the future returned from close. |
56 */ | 67 */ |
57 Future get done; | 68 Future get done; |
58 } | 69 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 .whenComplete(() { | 103 .whenComplete(() { |
93 _isBound = false; | 104 _isBound = false; |
94 }); | 105 }); |
95 } | 106 } |
96 if (_controllerInstance == null) return targetAddStream(); | 107 if (_controllerInstance == null) return targetAddStream(); |
97 var future = _controllerCompleter.future; | 108 var future = _controllerCompleter.future; |
98 _controllerInstance.close(); | 109 _controllerInstance.close(); |
99 return future.then((_) => targetAddStream()); | 110 return future.then((_) => targetAddStream()); |
100 } | 111 } |
101 | 112 |
| 113 Future flush() { |
| 114 // Adding an empty stream-controller will return a future that will complete |
| 115 // when all data is done. |
| 116 var controller = new StreamController()..close(); |
| 117 return addStream(controller.stream).then((_) => this); |
| 118 } |
| 119 |
102 Future close() { | 120 Future close() { |
103 if (_isBound) { | 121 if (_isBound) { |
104 throw new StateError("StreamSink is bound to a stream"); | 122 throw new StateError("StreamSink is bound to a stream"); |
105 } | 123 } |
106 if (!_isClosed) { | 124 if (!_isClosed) { |
107 _isClosed = true; | 125 _isClosed = true; |
108 if (_controllerInstance != null) { | 126 if (_controllerInstance != null) { |
109 _controllerInstance.close(); | 127 _controllerInstance.close(); |
110 } else { | 128 } else { |
111 _closeTarget(); | 129 _closeTarget(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 243 |
226 void writeln([Object obj = ""]) { | 244 void writeln([Object obj = ""]) { |
227 write(obj); | 245 write(obj); |
228 write("\n"); | 246 write("\n"); |
229 } | 247 } |
230 | 248 |
231 void writeCharCode(int charCode) { | 249 void writeCharCode(int charCode) { |
232 write(new String.fromCharCode(charCode)); | 250 write(new String.fromCharCode(charCode)); |
233 } | 251 } |
234 } | 252 } |
OLD | NEW |