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

Side by Side Diff: sdk/lib/async/stream.dart

Issue 15999002: Add Stream.drain() method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up impl and comments. Created 7 years, 7 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 | « no previous file | tests/lib/async/stream_controller_async_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.async; 5 part of dart.async;
6 6
7 // ------------------------------------------------------------------- 7 // -------------------------------------------------------------------
8 // Core Stream types 8 // Core Stream types
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 10
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 }, 492 },
493 onError: future._setError, 493 onError: future._setError,
494 onDone: () { 494 onDone: () {
495 future._setValue(result); 495 future._setValue(result);
496 }, 496 },
497 cancelOnError: true); 497 cancelOnError: true);
498 return future; 498 return future;
499 } 499 }
500 500
501 /** 501 /**
502 * Discards all data on the stream, but signals when it's done or an error
503 * occured.
504 *
505 * When subscribing using [drain], cancelOnError will be true. This means
506 * that the future will complete with the first error on the stream and then
507 * cancel the subscription.
508 *
509 * In case of a `done` event the future completes with the given
510 * [futureValue].
511 */
512 Future drain([var futureValue]) => listen(null, cancelOnError: true)
513 .asFuture(futureValue);
514
515 /**
502 * Provides at most the first [n] values of this stream. 516 * Provides at most the first [n] values of this stream.
503 * 517 *
504 * Forwards the first [n] data events of this stream, and all error 518 * Forwards the first [n] data events of this stream, and all error
505 * events, to the returned stream, and ends with a done event. 519 * events, to the returned stream, and ends with a done event.
506 * 520 *
507 * If this stream produces fewer than [count] values before it's done, 521 * If this stream produces fewer than [count] values before it's done,
508 * so will the returned stream. 522 * so will the returned stream.
509 */ 523 */
510 Stream<T> take(int count) { 524 Stream<T> take(int count) {
511 return new _TakeStream(this, count); 525 return new _TakeStream(this, count);
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 } 1226 }
1213 1227
1214 class _EventOutputSinkWrapper<T> extends EventSink<T> { 1228 class _EventOutputSinkWrapper<T> extends EventSink<T> {
1215 _EventOutputSink _sink; 1229 _EventOutputSink _sink;
1216 _EventOutputSinkWrapper(this._sink); 1230 _EventOutputSinkWrapper(this._sink);
1217 1231
1218 void add(T data) { _sink._sendData(data); } 1232 void add(T data) { _sink._sendData(data); }
1219 void addError(error) { _sink._sendError(error); } 1233 void addError(error) { _sink._sendError(error); }
1220 void close() { _sink._sendDone(); } 1234 void close() { _sink._sendDone(); }
1221 } 1235 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/async/stream_controller_async_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698