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

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

Issue 1462743002: add generic method comments to a few SDK methods (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 310 }
311 311
312 /** 312 /**
313 * Creates a new stream that converts each element of this stream 313 * Creates a new stream that converts each element of this stream
314 * to a new value using the [convert] function. 314 * to a new value using the [convert] function.
315 * 315 *
316 * The returned stream is a broadcast stream if this stream is. 316 * The returned stream is a broadcast stream if this stream is.
317 * If a broadcast stream is listened to more than once, each subscription 317 * If a broadcast stream is listened to more than once, each subscription
318 * will individually execute `map` for each event. 318 * will individually execute `map` for each event.
319 */ 319 */
320 Stream map(convert(T event)) { 320 Stream/*<S>*/ map/*<S>*/(/*=S*/ convert(T event)) {
321 return new _MapStream<T, dynamic>(this, convert); 321 return new _MapStream<T, dynamic/*=S*/>(this, convert);
322 } 322 }
323 323
324 /** 324 /**
325 * Creates a new stream with each data event of this stream asynchronously 325 * Creates a new stream with each data event of this stream asynchronously
326 * mapped to a new event. 326 * mapped to a new event.
327 * 327 *
328 * This acts like [map], except that [convert] may return a [Future], 328 * This acts like [map], except that [convert] may return a [Future],
329 * and in that case, the stream waits for that future to complete before 329 * and in that case, the stream waits for that future to complete before
330 * continuing with its result. 330 * continuing with its result.
331 * 331 *
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 * into zero or more events. 472 * into zero or more events.
473 * 473 *
474 * Each incoming event is converted to an [Iterable] of new events, 474 * Each incoming event is converted to an [Iterable] of new events,
475 * and each of these new events are then sent by the returned stream 475 * and each of these new events are then sent by the returned stream
476 * in order. 476 * in order.
477 * 477 *
478 * The returned stream is a broadcast stream if this stream is. 478 * The returned stream is a broadcast stream if this stream is.
479 * If a broadcast stream is listened to more than once, each subscription 479 * If a broadcast stream is listened to more than once, each subscription
480 * will individually call `convert` and expand the events. 480 * will individually call `convert` and expand the events.
481 */ 481 */
482 Stream expand(Iterable convert(T value)) { 482 Stream/*<S>*/ expand(Iterable/*<S>*/ convert(T value)) {
483 return new _ExpandStream<T, dynamic>(this, convert); 483 return new _ExpandStream<T, dynamic/*=S*/>(this, convert);
484 } 484 }
485 485
486 /** 486 /**
487 * Pipe the events of this stream into [streamConsumer]. 487 * Pipe the events of this stream into [streamConsumer].
488 * 488 *
489 * The events of this stream are added to `streamConsumer` using 489 * The events of this stream are added to `streamConsumer` using
490 * [StreamConsumer.addStream]. 490 * [StreamConsumer.addStream].
491 * The `streamConsumer` is closed when this stream has been successfully added 491 * The `streamConsumer` is closed when this stream has been successfully added
492 * to it - when the future returned by `addStream` completes without an error. 492 * to it - when the future returned by `addStream` completes without an error.
493 * 493 *
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } else { 547 } else {
548 result._complete(value); 548 result._complete(value);
549 } 549 }
550 }, 550 },
551 cancelOnError: true 551 cancelOnError: true
552 ); 552 );
553 return result; 553 return result;
554 } 554 }
555 555
556 /** Reduces a sequence of values by repeatedly applying [combine]. */ 556 /** Reduces a sequence of values by repeatedly applying [combine]. */
557 Future fold(var initialValue, combine(var previous, T element)) { 557 Future/*<S>*/ fold/*<S>*/(var/*=S*/ initialValue,
558 /*=S*/ combine(var/*=S*/ previous, T element)) {
559
558 _Future result = new _Future(); 560 _Future result = new _Future();
559 var value = initialValue; 561 var value = initialValue;
560 StreamSubscription subscription; 562 StreamSubscription subscription;
561 subscription = this.listen( 563 subscription = this.listen(
562 (T element) { 564 (T element) {
563 _runUserCode( 565 _runUserCode(
564 () => combine(value, element), 566 () => combine(value, element),
565 (newValue) { value = newValue; }, 567 (newValue) { value = newValue; },
566 _cancelAndErrorClosure(subscription, result) 568 _cancelAndErrorClosure(subscription, result)
567 ); 569 );
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 class _ControllerEventSinkWrapper<T> implements EventSink<T> { 1743 class _ControllerEventSinkWrapper<T> implements EventSink<T> {
1742 EventSink _sink; 1744 EventSink _sink;
1743 _ControllerEventSinkWrapper(this._sink); 1745 _ControllerEventSinkWrapper(this._sink);
1744 1746
1745 void add(T data) { _sink.add(data); } 1747 void add(T data) { _sink.add(data); }
1746 void addError(error, [StackTrace stackTrace]) { 1748 void addError(error, [StackTrace stackTrace]) {
1747 _sink.addError(error, stackTrace); 1749 _sink.addError(error, stackTrace);
1748 } 1750 }
1749 void close() { _sink.close(); } 1751 void close() { _sink.close(); }
1750 } 1752 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698