How to add, prepend and append value in MutableStateFlow in Kotlin

A SharedFlow or StateFlow has no end unless it's cancelled. Calling collect or collectLatest on it is sort of like creating a while(true) loop. It will never finish iterating because it's always possible it will have another value emitted.

In the documentation you can read about it in the section that starts with"Shared flow never completes.".