Skip to content

Add internal WatchManager class#80

Open
LucDeCaf wants to merge 2 commits into
mainfrom
internal-watch-rewrite
Open

Add internal WatchManager class#80
LucDeCaf wants to merge 2 commits into
mainfrom
internal-watch-rewrite

Conversation

@LucDeCaf

Copy link
Copy Markdown
Contributor

Adds a WatchManager class that manages watched queries, replacing the in-class implementation in PowerSyncDatabase. The old code for watches was difficult to reason about and contained a lot of monkey-patching to support async iterators and schema resets triggering interruptions. This new approach moves all the logic into a dedicated WatchManager class which manages the watch subscription lifecycle and is designed from the ground up with async iterator support and schema resets in mind.

Main differences

  • PowerSyncDatabase.Watch / PowerSyncDatabase.OnChange are now wrappers around WatchManager methods.
  • SchemaChanged event is no longer emitted on DB initialization (subject to change).
  • WatchManager maintains one TablesUpdated event listener which is shared across multiple watches.

Also fixes a bug in the Watch_SchemaReset test where DB initialisation was not awaited, causing the test to frequently time out on the windows-11-arm runner.

AI Usage

I blocked out the WatchManager and WatchSubscription classes and wired them up to PowerSyncDatabase and implemented the plumbing methods for WatchManager (Stream, RequestRefresh, CreateSubscription, etc.). I then asked Fable 5 to implement the watch logic using the old code as a reference and edited the results manually to fix some small errors and styling mistakes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant