Skip to content

Commit c98ee0b

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Fix and update StreamTransformer constructor documentation.
Fixes #46924 BUG= https://dartbug.com/46924 Change-Id: I8a5d2aa3f60680ec419c4f0d614f6ec186106b08 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210360 Auto-Submit: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Nate Bosch <[email protected]> Commit-Queue: Nate Bosch <[email protected]>
1 parent 099c5a5 commit c98ee0b

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

sdk/lib/async/stream.dart

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,28 +1913,24 @@ abstract class StreamTransformer<S, T> {
19131913
/// ```dart
19141914
/// /// Starts listening to [input] and duplicates all non-error events.
19151915
/// StreamSubscription<int> _onListen(Stream<int> input, bool cancelOnError) {
1916-
/// late StreamSubscription<String> subscription;
1917-
/// // Create controller that forwards pause, resume and cancel events.
1918-
/// var controller = new StreamController<String>(
1919-
/// onPause: () {
1920-
/// subscription.pause();
1921-
/// },
1922-
/// onResume: () {
1923-
/// subscription.resume();
1924-
/// },
1925-
/// onCancel: () => subscription.cancel(),
1926-
/// sync: true); // "sync" is correct here, since events are forwarded.
1927-
///
1928-
/// // Listen to the provided stream.
1929-
/// subscription = input.listen((data) {
1930-
/// // Duplicate the data.
1931-
/// controller.add(data);
1932-
/// controller.add(data);
1933-
/// },
1934-
/// onError: controller.addError,
1935-
/// onDone: controller.close,
1936-
/// cancelOnError: cancelOnError);
1937-
///
1916+
/// // Create the result controller.
1917+
/// // Using `sync` is correct here, since only async events are forwarded.
1918+
/// var controller = StreamController<int>(sync: true);
1919+
/// controller.onListen = () {
1920+
/// var subscription = input.listen((data) {
1921+
/// // Duplicate the data.
1922+
/// controller.add(data);
1923+
/// controller.add(data);
1924+
/// },
1925+
/// onError: controller.addError,
1926+
/// onDone: controller.close,
1927+
/// cancelOnError: cancelOnError);
1928+
/// // Controller forwards pause, resume and cancel events.
1929+
/// controller
1930+
/// ..onPause = subscription.pause
1931+
/// ..onResume = subscription.resume
1932+
/// ..onCancel = subscription.cancel;
1933+
/// };
19381934
/// // Return a new [StreamSubscription] by listening to the controller's
19391935
/// // stream.
19401936
/// return controller.stream.listen(null);

0 commit comments

Comments
 (0)