Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamTransformer default constructor documentation wrong? #46924

Closed
EP-u-NW opened this issue Aug 16, 2021 · 3 comments
Closed

StreamTransformer default constructor documentation wrong? #46924

EP-u-NW opened this issue Aug 16, 2021 · 3 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-async type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) type-documentation A request to add or improve documentation

Comments

@EP-u-NW
Copy link

EP-u-NW commented Aug 16, 2021

The documentation for StreamTransformer() in dart 2.13.4 lists the following example:

/// Starts listening to [input] and duplicates all non-error events.
StreamSubscription<int> _onListen(Stream<int> input, bool cancelOnError) {
  late StreamSubscription<String> subscription;
  // Create controller that forwards pause, resume and cancel events.
  var controller = new StreamController<String>(
      onPause: () {
        subscription.pause();
      },
      onResume: () {
        subscription.resume();
      },
      onCancel: () => subscription.cancel(),
      sync: true); // "sync" is correct here, since events are forwarded.

  // Listen to the provided stream.
  subscription = input.listen((data) {
    // Duplicate the data.
    controller.add(data);
    controller.add(data);
  },
      onError: controller.addError,
      onDone: controller.close,
      cancelOnError: cancelOnError);

  // Return a new [StreamSubscription] by listening to the controller's
  // stream.
  return controller.stream.listen(null);
}

// Instantiate a transformer:
var duplicator = const StreamTransformer<int, int>(_onListen);

// Use as follows:
intStream.transform(duplicator);

As far as I can see, the type arguments for subscription and controller should be int, not String?

@vsmenon vsmenon added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-async labels Aug 16, 2021
@Levi-Lesches
Copy link

I copied the code to Dartpad and verified that changing controller to Stream<int> fixes all the errors.

@lrhn lrhn self-assigned this Aug 17, 2021
@lrhn lrhn added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) type-documentation A request to add or improve documentation labels Aug 17, 2021
@lrhn
Copy link
Member

lrhn commented Aug 17, 2021

The code is also not a particularly good example any more, I'll rewrite it to something modern.

@EP-u-NW
Copy link
Author

EP-u-NW commented Aug 17, 2021

The code is also not a particularly good example any more, I'll rewrite it to something modern.

Good to hear that, I already started basing my code for an SyncStreamTransformer on it 😁. I will wait then for the next example 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-async type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) type-documentation A request to add or improve documentation
Projects
None yet
Development

No branches or pull requests

3 participants