Skip to content

Stream transformations shouldn't preserve broadcast state #18586

@nex3

Description

@nex3

From the Stream documentation: "Stream transformations, such as where and skip, always return non-broadcast streams."

The following code snippet demonstrates that this isn't consistently true among transformation methods:

    void main() {
      var stream = new StreamController.broadcast().stream;
      testBroadcast("asyncExpand",
          stream.asyncExpand((e) => new Stream.fromIterable([e])));
      testBroadcast("asyncMap", stream.asyncMap((e) => e));
      testBroadcast("distinct", stream.distinct());
      testBroadcast("expand", stream.expand((e) => [e]));
      testBroadcast("handleError", stream.handleError((e) => throw e));
      testBroadcast("map", stream.map((e) => e));
      testBroadcast("skip", stream.skip(1));
      testBroadcast("skipWhile", stream.skipWhile(() => false));
      testBroadcast("takeWhile", stream.skipWhile((
) => true));
      testBroadcast("timeout", stream.timeout(new Duration(seconds: 5)));
      testBroadcast("transform",
          stream.transform(new StreamTransformer.fromHandlers()));
      testBroadcast("where", stream.where((_) => true));
    }

    void testBroadcast(String name, Stream stream) {
      print("$name ${stream.isBroadcast ? 'is' : 'is not'} broadcast");
    }

This prints:

    asyncExpand is not broadcast
    asyncMap is not broadcast
    distinct is broadcast
    expand is broadcast
    handleError is broadcast
    map is broadcast
    skip is broadcast
    skipWhile is broadcast
    takeWhile is broadcast
    timeout is not broadcast
    transform is not broadcast
    where is broadcast

Most transformations, including "where" and "skip" which are explicitly called out as not preserving the broadcast state, do in fact preserve it.

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-async

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions