For ViewModels that are updated very quickly, it may be desirable to skip some State emissions in order to not overload the disk and make sure that writes to the disk don't slow down the main ViewModel's processing.
To that end, all writes should be persisted asynchronously, and a configurable delay between emissions. By default, the delay will be 0. If there is a delay, then that much time will wait before sending the state to the adapter. If a new State is emitted before that delay completes, then the latest State value will be persisted. This needs to be more clever than a simple .mapLatest, as we don't want to reset the timer because emissions may continually prevent the adapter from ever being called.
bufferFlow parameter added to BallastSavedStateInterceptor in 2.0.0, which allows user-specified buffering/filtering on the States as they are sent to be saved
For ViewModels that are updated very quickly, it may be desirable to skip some State emissions in order to not overload the disk and make sure that writes to the disk don't slow down the main ViewModel's processing.
To that end, all writes should be persisted asynchronously, and a configurable delay between emissions. By default, the delay will be 0. If there is a delay, then that much time will wait before sending the state to the adapter. If a new State is emitted before that delay completes, then the latest State value will be persisted. This needs to be more clever than a simple
.mapLatest
, as we don't want to reset the timer because emissions may continually prevent the adapter from ever being called.