felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.53k stars 3.37k forks source link

question: [flutter_todos] why don't close StreamController? #4154

Closed manuelperez96 closed 2 months ago

manuelperez96 commented 2 months ago

Description

Hi, I'm learning about bloc-to-bloc communication through domain layer using streams. I was looking the example flutter_todos and I realised that local_storage_todos_api use an StreamController, but this is never closed.

This is not a bad practice? Is there some motive to not close this Stream Controller?

Thank you.

felangel commented 2 months ago

Hi @manuelperez96 👋 Thanks for opening an issue!

In this case, the lifecycle of the LocalStorageTodosApi is tied to the application (e.g. the LocalStorageTodosApi is active the entire time the application is running) so it's okay that the underlying controller isn't closed. I opened #4157 to add a close API to the TodosApi in order to encourage cleaning up internal resources in general since in some cases the TodosApi might be created/destroyed multiple times throughout the lifetime of the app.

Hope that clears things up and thanks for raising this issue! 👍