Skip to content

MultiStreamController.onListen is never called? #56925

@sgrekhov

Description

@sgrekhov
import "dart:async";
import "../../../Utils/expect.dart";

main() {
  asyncStart(2);
  var stream = Stream<int>.multi((controller) {
    controller.onListen = () {
      print("onListen"); // Not printed
      asyncEnd();
    };
    controller.add(1);
    controller.add(2);
    controller.add(3);
    controller.close();
  });
  listen(stream);
  listen(stream);
}

void listen(Stream<int> stream) {
  int i = 0;
  stream.listen((v) {
    Expect.equals(++i, v);
  }, onDone: () {
    Expect.equals(3, i);
  });
}

According to the documentation "The callback which is called when the stream is listened to.". Why it is not called in the code above?

cc @lrhn

Dart SDK version: 3.7.0-27.0.dev (dev) (Tue Oct 15 17:02:51 2024 -0700) on "windows_x64"

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 documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions