Skip to content

[DO NOT MERGE] Notify SourceOfTruthWithBarrier on delete and deleteAll (#731) - #768

Open
binayshaw7777 wants to merge 2 commits into
MobileNativeFoundation:mainfrom
binayshaw7777:binay/fix-clear-sot-barrier
Open

binayshaw7777 wants to merge 2 commits into
MobileNativeFoundation:mainfrom
binayshaw7777:binay/fix-clear-sot-barrier

Conversation

@binayshaw7777

Copy link
Copy Markdown

Closes #731

Description

When store.clear(key) or store.clear() was called, SourceOfTruthWithBarrier.delete() and deleteAll() forwarded the call directly to the delegate without notifying barriers (MutableStateFlow<BarrierMsg>).

As a result:

  • Active stream readers on non-flowing persisters (PersistentNonFlowingSourceOfTruth) never knew the data was deleted.
  • barrier.flatMapLatest was never re-evaluated, leaving stream collectors holding stale in-memory state and failing to trigger downstream network refetches.

This PR ensures:

  1. RefCountedResource exposes active keys.
  2. SourceOfTruthWithBarrier.delete() and deleteAll() acquire and transition barriers to Blocked, execute delegate deletion, and reopen with isDelete = true and incremented versions.
  3. Active reader flows are notified immediately and emit updated SourceOfTruth state.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Test Plan

  • Added deleteNotifiesActiveReaderFlow in SourceOfTruthWithBarrierTests.kt confirming that an active reader flow receives an emission when delete(key) is invoked.
  • Verified test suite passes locally with ./gradlew :store:jvmTest.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective
  • New and existing unit tests pass locally with my changes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 Triage

Development

Successfully merging this pull request may close these issues.

[BUG] store.clear does not trigger a refetch in the collected stream (not sure if this is a bug or expected behavior)

1 participant