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

Side by Side Diff: sdk/lib/io/io_sink.dart

Issue 13680002: StreamConsumer has an addStream and a close functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | « sdk/lib/io/http_parser.dart ('k') | tests/lib/async/slow_consumer2_test.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) 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>, T>] and provide 8 * Helper class to wrap a [StreamConsumer<List<int>, T>] 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 [write], [writeAll], [writeln], 10 * [IOSink] buffers the input given by [write], [writeAll], [writeln],
(...skipping 19 matching lines...) Expand all
30 * Writes the bytes uninterpreted to the consumer. 30 * Writes the bytes uninterpreted to the consumer.
31 */ 31 */
32 void writeBytes(List<int> data); 32 void writeBytes(List<int> data);
33 33
34 /** 34 /**
35 * Provide functionality for piping to the [IOSink]. 35 * Provide functionality for piping to the [IOSink].
36 */ 36 */
37 Future<T> consume(Stream<List<int>> stream); 37 Future<T> consume(Stream<List<int>> stream);
38 38
39 /** 39 /**
40 * Provide functionality for piping to the [IOSink].
41 */
42 Future<T> addStream(Stream<List<int>> stream);
43
44 /**
40 * Like [consume], but will not close the target when done. 45 * Like [consume], but will not close the target when done.
41 */ 46 */
42 Future<T> writeStream(Stream<List<int>> stream); 47 Future<T> writeStream(Stream<List<int>> stream);
Søren Gjesse 2013/04/05 05:23:19 The plan is then to remove this in a future CL? We
floitsch 2013/04/05 16:21:32 Done.
43 48
44 /** 49 /**
45 * Close the target. 50 * Close the target.
46 */ 51 */
47 void close(); 52 // TODO(floitsch): Currently the future cannot be typed because it has
53 // hardcoded type Future<HttpClientResponse> in subclass HttpClientRequest.
54 Future close();
48 55
49 /** 56 /**
50 * Get future that will complete when all data has been written to 57 * Get future that will complete when all data has been written to
51 * the IOSink and it has been closed. 58 * the IOSink and it has been closed.
52 */ 59 */
53 Future<T> get done; 60 Future<T> get done;
54 } 61 }
55 62
56 63
57 class _IOSinkImpl<T> implements IOSink<T> { 64 class _IOSinkImpl<T> implements IOSink<T> {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 134 }
128 135
129 Future<T> consume(Stream<List<int>> stream) { 136 Future<T> consume(Stream<List<int>> stream) {
130 if (_isBound) { 137 if (_isBound) {
131 throw new StateError("IOSink is already bound to a stream"); 138 throw new StateError("IOSink is already bound to a stream");
132 } 139 }
133 return _fillFromStream(stream); 140 return _fillFromStream(stream);
134 } 141 }
135 142
136 Future<T> writeStream(Stream<List<int>> stream) { 143 Future<T> writeStream(Stream<List<int>> stream) {
144 return addStream(stream);
145 }
146
147 Future<T> addStream(Stream<List<int>> stream) {
137 if (_isBound) { 148 if (_isBound) {
138 throw new StateError("IOSink is already bound to a stream"); 149 throw new StateError("IOSink is already bound to a stream");
139 } 150 }
140 return _fillFromStream(stream, unbind: true); 151 return _fillFromStream(stream, unbind: true);
141 } 152 }
142 153
143 void close() { 154 Future close() {
144 if (_isBound) { 155 if (_isBound) {
145 throw new StateError("IOSink is already bound to a stream"); 156 throw new StateError("IOSink is already bound to a stream");
146 } 157 }
147 _controller.close(); 158 _controller.close();
159 return _pipeFuture;
148 } 160 }
149 161
150 Future<T> get done { 162 Future<T> get done {
151 _controller; 163 _controller;
152 return _pipeFuture; 164 return _pipeFuture;
153 } 165 }
154 166
155 void _completeWriteStreamCompleter([error]) { 167 void _completeWriteStreamCompleter([error]) {
156 if (_writeStreamCompleter == null) return; 168 if (_writeStreamCompleter == null) return;
157 var tmp = _writeStreamCompleter; 169 var tmp = _writeStreamCompleter;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 }, 249 },
238 onError: _controller.addError); 250 onError: _controller.addError);
239 if (_paused) _pause(); 251 if (_paused) _pause();
240 if (unbind) { 252 if (unbind) {
241 return _writeStreamCompleter.future; 253 return _writeStreamCompleter.future;
242 } else { 254 } else {
243 return _pipeFuture; 255 return _pipeFuture;
244 } 256 }
245 } 257 }
246 } 258 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | tests/lib/async/slow_consumer2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698