@@ -1913,28 +1913,24 @@ abstract class StreamTransformer<S, T> {
1913
1913
/// ```dart
1914
1914
/// /// Starts listening to [input] and duplicates all non-error events.
1915
1915
/// 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
+ /// };
1938
1934
/// // Return a new [StreamSubscription] by listening to the controller's
1939
1935
/// // stream.
1940
1936
/// return controller.stream.listen(null);
0 commit comments