Skip to content

Commit 9056b20

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Update various documentations.
Documents Stream.timeout better. Documents that collection.cast doesn't affect methods accepting `Object?`. Fixes #30163 Documents issue of #46336 Bug: http://dartbug.com/30163 Change-Id: Ie228a81d838a14c383da2f75af8b5dbb31e8ea3d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208651 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Commit-Queue: Erik Ernst <[email protected]> Auto-Submit: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent 9ec112a commit 9056b20

File tree

5 files changed

+65
-11
lines changed

5 files changed

+65
-11
lines changed

sdk/lib/async/stream.dart

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,24 +1479,31 @@ abstract class Stream<T> {
14791479

14801480
/// Creates a new stream with the same events as this stream.
14811481
///
1482-
/// Whenever more than [timeLimit] passes between two events from this stream,
1483-
/// the [onTimeout] function is called, which can emit further events on
1482+
/// When someone is listening on the returned stream and more than
1483+
/// [timeLimit] passes without any event being emitted by this stream,
1484+
/// the [onTimeout] function is called, which can then emit further events on
14841485
/// the returned stream.
14851486
///
1486-
/// The countdown doesn't start until the returned stream is listened to.
1487-
/// The countdown is reset every time an event is forwarded from this stream,
1488-
/// or when this stream is paused and resumed.
1487+
/// The countdown starts when the returned stream is listened to,
1488+
/// and is restarted when an event from the this stream is emitted,
1489+
/// or when listening on the returned stream is paused and resumed.
1490+
/// The countdown is stopped when listening on the returned stream is
1491+
/// paused or cancelled.
1492+
/// No new countdown is started when a countdown completes
1493+
/// and the [onTimeout] function is called, even if events are emitted.
1494+
/// If the delay between events of this stream is multiple times
1495+
/// [timeLimit], at most one timeout will happen between events.
14891496
///
14901497
/// The [onTimeout] function is called with one argument: an
14911498
/// [EventSink] that allows putting events into the returned stream.
14921499
/// This `EventSink` is only valid during the call to [onTimeout].
14931500
/// Calling [EventSink.close] on the sink passed to [onTimeout] closes the
14941501
/// returned stream, and no further events are processed.
14951502
///
1496-
/// If [onTimeout] is omitted, a timeout will just put a [TimeoutException]
1503+
/// If [onTimeout] is omitted, a timeout will emit a [TimeoutException]
14971504
/// into the error channel of the returned stream.
1498-
/// If the call to [onTimeout] throws, the error is emitted on the returned
1499-
/// stream.
1505+
/// If the call to [onTimeout] throws, the error is emitted as an error
1506+
/// on the returned stream.
15001507
///
15011508
/// The returned stream is a broadcast stream if this stream is.
15021509
/// If a broadcast stream is listened to more than once, each subscription
@@ -1519,8 +1526,6 @@ abstract class Stream<T> {
15191526
new TimeoutException("No stream event", timeLimit), null);
15201527
};
15211528
} else {
1522-
// TODO(floitsch): the return type should be 'void', and the type
1523-
// should be inferred.
15241529
var registeredOnTimeout =
15251530
zone.registerUnaryCallback<void, EventSink<T>>(onTimeout);
15261531
var wrapper = new _ControllerEventSinkWrapper<T>(null);

sdk/lib/collection/queue.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ abstract class Queue<E> implements EfficientLengthIterable<E> {
5252
/// and if all elements stored into the returned queue are actually instance
5353
/// of [S],
5454
/// then the returned queue can be used as a `Queue<T>`.
55+
///
56+
/// Methods like [contains] and [remove]
57+
/// which accept one `Object?` as argument,
58+
/// will pass the argument directly to the this queue's method
59+
/// without any checks.
5560
static Queue<T> castFrom<S, T>(Queue<S> source) => CastQueue<S, T>(source);
5661

5762
/// Provides a view of this queue as a queue of [R] instances, if necessary.
@@ -64,6 +69,13 @@ abstract class Queue<E> implements EfficientLengthIterable<E> {
6469
/// must be instance of [R] to be valid arguments to the adding function,
6570
/// and they must be instances of [E] as well to be accepted by
6671
/// this queue as well.
72+
///
73+
/// Methods like [contains] and [remove]
74+
/// which accept one `Object?` as argument,
75+
/// will pass the argument directly to the this queue's method
76+
/// without any checks.
77+
/// That means that you can do `queueOfStrings.cast<int>().remove("a")`
78+
/// successfully, even if it looks like it shouldn't have any effect.
6779
Queue<R> cast<R>();
6880

6981
/// Removes and returns the first element of this queue.
@@ -304,6 +316,7 @@ class DoubleLinkedQueue<E> extends Iterable<E> implements Queue<E> {
304316
DoubleLinkedQueue<E>()..addAll(elements);
305317

306318
Queue<R> cast<R>() => Queue.castFrom<E, R>(this);
319+
307320
int get length => _elementCount;
308321

309322
void addLast(E value) {

sdk/lib/core/list.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ abstract class List<E> implements EfficientLengthIterable<E> {
187187
/// and if all elements stored into the returned list are actually instance
188188
/// of [S],
189189
/// then the returned list can be used as a `List<T>`.
190+
///
191+
/// Methods like [contains] and [remove]
192+
/// which accept `Object?` as argument
193+
/// will pass the argument directly to the this list's method
194+
/// without any checks.
190195
static List<T> castFrom<S, T>(List<S> source) => CastList<S, T>(source);
191196

192197
/// Copy a range of one list into another list.
@@ -254,14 +259,21 @@ abstract class List<E> implements EfficientLengthIterable<E> {
254259
/// Returns a view of this list as a list of [R] instances.
255260
///
256261
/// If this list contains only instances of [R], all read operations
257-
/// will work correctly. If any operation tries to access an element
262+
/// will work correctly. If any operation tries to read an element
258263
/// that is not an instance of [R], the access will throw instead.
259264
///
260265
/// Elements added to the list (e.g., by using [add] or [addAll])
261266
/// must be instance of [R] to be valid arguments to the adding function,
262267
/// and they must be instances of [E] as well to be accepted by
263268
/// this list as well.
264269
///
270+
/// Methods like [contains] and [remove]
271+
/// which accept `Object?` as argument
272+
/// will pass the argument directly to the this list's method
273+
/// without any checks.
274+
/// That means that you can do `listOfStrings.cast<int>().remove("a")`
275+
/// successfully, even if it looks like it shouldn't have any effect.
276+
///
265277
/// Typically implemented as `List.castFrom<E, R>(this)`.
266278
List<R> cast<R>();
267279

sdk/lib/core/map.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ abstract class Map<K, V> {
163163
/// If all accessed entries of [source] are have [K2] keys and [V2] values
164164
/// and if all entries added to the returned map have [K] keys and [V]] values,
165165
/// then the returned map can be used as a `Map<K2, V2>`.
166+
///
167+
/// Methods like [containsKey], [remove] and [operator[]]
168+
/// which accept `Object?` as argument
169+
/// will pass the argument directly to the this map's method
170+
/// without any checks.
166171
static Map<K2, V2> castFrom<K, V, K2, V2>(Map<K, V> source) =>
167172
CastMap<K, V, K2, V2>(source);
168173

@@ -193,6 +198,13 @@ abstract class Map<K, V> {
193198
///
194199
/// Entries added to the map must be valid for both a `Map<K, V>` and a
195200
/// `Map<RK, RV>`.
201+
///
202+
/// Methods like [containsKey], [remove] and [operator[]]
203+
/// which accept `Object?` as argument
204+
/// will pass the argument directly to the this map's method
205+
/// without any checks.
206+
/// That means that you can do `mapWithStringKeys.cast<int,int>().remove("a")`
207+
/// successfully, even if it looks like it shouldn't have any effect.
196208
Map<RK, RV> cast<RK, RV>();
197209

198210
/// Whether this map contains the given [value].

sdk/lib/core/set.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ abstract class Set<E> extends EfficientLengthIterable<E> {
106106
/// and if all elements added to the returned set are actually instance
107107
/// of [S],
108108
/// then the returned set can be used as a `Set<T>`.
109+
///
110+
/// Methods like [contains], [remove] and [removeAll]
111+
/// which accept one or more `Object?` as argument,
112+
/// will pass the argument directly to the this set's method
113+
/// without any checks.
109114
static Set<T> castFrom<S, T>(Set<S> source, {Set<R> Function<R>()? newSet}) =>
110115
CastSet<S, T>(source, newSet);
111116

@@ -119,6 +124,13 @@ abstract class Set<E> extends EfficientLengthIterable<E> {
119124
/// must be instance of [R] to be valid arguments to the adding function,
120125
/// and they must be instances of [E] as well to be accepted by
121126
/// this set as well.
127+
///
128+
/// Methods like [contains], [remove] and [removeAll]
129+
/// which accept one or more `Object?` as argument,
130+
/// will pass the argument directly to the this set's method
131+
/// without any checks.
132+
/// That means that you can do `setOfStrings.cast<int>().remove("a")`
133+
/// successfully, even if it looks like it shouldn't have any effect.
122134
Set<R> cast<R>();
123135

124136
/// An iterator that iterates over the elements of this set.

0 commit comments

Comments
 (0)