Skip to content

Is a stream created by Stream.multi() always a multi-subscription stream? #56903

@sgrekhov

Description

@sgrekhov

According to Stream.multi documentation

/// Creates a multi-subscription stream.

It's not quite true in the case when a source of MultiStreamController.addStream() is a single-subscription stream. For example:

main() {
  var source = StreamController<int>();
  source.add(1);
  source.add(2);
  source.add(3);
  source.close();

  var stream = Stream<int>.multi((controller) {
    controller.addStream(source.stream).then((_) {
      controller.close();
    });
  });
  listen(stream);
  listen(stream); // Bad state: Stream has already been listened to.
}

void listen(Stream<int> stream) {
  int eventsCounter = 1;
  stream.listen((v) {
    Expect.equals(eventsCounter++, v);
  }, onDone: () {
    Expect.equals(4, eventsCounter);
  });
}

Is this expected? If yes, then, probably, it makes sense to reflect it in the Stream.multi() constructor documentation.

cc @lrhn

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-asynctype-documentationA request to add or improve documentationtype-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions