Skip to content

Commit e601ca5

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Updates documentation of StreamController.close and .done.
Fixes #19095 BUG= http://dartbug.com/19095 http://dartbug.com/27203 Change-Id: I6cbf9fb3f8151ab43da6cf47c8d4ab4282d53539 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96600 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Nate Bosch <[email protected]>
1 parent fc1ecda commit e601ca5

File tree

2 files changed

+62
-15
lines changed

2 files changed

+62
-15
lines changed

sdk/lib/async/stream_controller.dart

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,40 @@ abstract class StreamController<T> implements StreamSink<T> {
249249
/**
250250
* Closes the stream.
251251
*
252-
* Listeners receive the done event at a later microtask. This behavior can be
253-
* overridden by using `sync` controllers. Note, however, that sync
254-
* controllers have to satisfy the preconditions mentioned in the
255-
* documentation of the constructors.
252+
* No further events can be added to a closed stream.
253+
*
254+
* The returned future is the same future provided by [done].
255+
* It is completed when the stream listeners is done sending events,
256+
* This happens either when the done event has been sent,
257+
* or when the subscriber on a single-subscription stream is canceled.
258+
*
259+
* A broadcast stream controller will send the done event
260+
* even if listeners are paused, so some broadcast events may not have been
261+
* received yet when the returned future completes.
262+
*
263+
* If noone listens to a non-broadcast stream,
264+
* or the listener pauses and never resumes,
265+
* the done event will not be sent and this future will never complete.
256266
*/
257267
Future close();
258268

269+
/**
270+
* A future which is completed when the stream controller is done
271+
* sending events.
272+
*
273+
* This happens either when the done event has been sent, or if the
274+
* subscriber on a single-subscription stream is canceled.
275+
*
276+
* A broadcast stream controller will send the done event
277+
* even if listeners are paused, so some broadcast events may not have been
278+
* received yet when the returned future completes.
279+
*
280+
* If there is no listener on a non-broadcast stream,
281+
* or the listener pauses and never resumes,
282+
* the done event will not be sent and this future will never complete.
283+
*/
284+
Future get done;
285+
259286
/**
260287
* Receives events from [source] and puts them into this controller's stream.
261288
*
@@ -575,13 +602,6 @@ abstract class _StreamController<T> implements _StreamControllerBase<T> {
575602
return addState.addStreamFuture;
576603
}
577604

578-
/**
579-
* Returns a future that is completed when the stream is done
580-
* processing events.
581-
*
582-
* This happens either when the done event has been sent, or if the
583-
* subscriber of a single-subscription stream is cancelled.
584-
*/
585605
Future get done => _ensureDoneFuture();
586606

587607
Future _ensureDoneFuture() {

sdk_nnbd/lib/async/stream_controller.dart

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,40 @@ abstract class StreamController<T> implements StreamSink<T> {
245245
/**
246246
* Closes the stream.
247247
*
248-
* Listeners receive the done event at a later microtask. This behavior can be
249-
* overridden by using `sync` controllers. Note, however, that sync
250-
* controllers have to satisfy the preconditions mentioned in the
251-
* documentation of the constructors.
248+
* No further events can be added to a closed stream.
249+
*
250+
* The returned future is the same future provided by [done].
251+
* It is completed when the stream listeners is done sending events,
252+
* This happens either when the done event has been sent,
253+
* or when the subscriber on a single-subscription stream is canceled.
254+
*
255+
* A broadcast stream controller will send the done event
256+
* even if listeners are paused, so some broadcast events may not have been
257+
* received yet when the returned future completes.
258+
*
259+
* If noone listens to a non-broadcast stream,
260+
* or the listener pauses and never resumes,
261+
* the done event will not be sent and this future will never complete.
252262
*/
253263
Future close();
254264

265+
/**
266+
* A future which is completed when the stream controller is done
267+
* sending events.
268+
*
269+
* This happens either when the done event has been sent, or if the
270+
* subscriber on a single-subscription stream is canceled.
271+
*
272+
* A broadcast stream controller will send the done event
273+
* even if listeners are paused, so some broadcast events may not have been
274+
* received yet when the returned future completes.
275+
*
276+
* If there is no listener on a non-broadcast stream,
277+
* or the listener pauses and never resumes,
278+
* the done event will not be sent and this future will never complete.
279+
*/
280+
Future get done;
281+
255282
/**
256283
* Receives events from [source] and puts them into this controller's stream.
257284
*

0 commit comments

Comments
 (0)