Skip to content

Allow sending events in a StreamController's onListen callback. #30532

Open
@lrhn

Description

@lrhn

The current contract for using synchronous stream controllers say that you must not send events immediately in the onListen callback.

Allowing this would make it easier to implement a Replay functionality by sending all events immediately, and then just staying up-to-speed with future events.

There is no problem doing this with an asynchronous completer because it won't send the event immediately, but a synchronous completer will send the event at a time where the listener might not have set up their callbacks yet (listener callbacks can be set on the subscription object instead of being passed in the listen call). In general, events occurring immediately when you call listen, before the subscription has been returned, has been found to be error-prone with the current API.

There is no combined sync/async controller that can send the first events asynchronously and later events synchronously, which might also handle the same issue.

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.core-2library-asynctype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions