Allow sending events in a StreamController's onListen callback. #30532
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
core-2
library-async
type-enhancement
A request for a change that isn't a bug
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.
The text was updated successfully, but these errors were encountered: