Skip to content

Commit

Permalink
Lock initial read in onStart (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharee authored and xxfast committed Dec 13, 2023
1 parent 1ae8888 commit d994963
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public class KStore<T : @Serializable Any>(
/** Observe store for updates */
public val updates: Flow<T?>
get() = this.cache
.onStart { read(fromCache = false) } // updates will always start with a fresh read
.onStart {
lock.withLock {
read(fromCache = false)
}
} // updates will always start with a fresh read

private suspend fun write(value: T?): Unit = withContext(StoreDispatcher) {
codec.encode(value)
Expand Down

0 comments on commit d994963

Please sign in to comment.