Skip to content

Web: Use navigator locks - #368

Draft
simolus3 wants to merge 5 commits into
update-depsfrom
navigator-locks
Draft

Web: Use navigator locks#368
simolus3 wants to merge 5 commits into
update-depsfrom
navigator-locks

Conversation

@simolus3

@simolus3 simolus3 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

To prevent multiple databases in the same process attempting to sync at the same time, we guard the sync client with a Mutex implementation from kotlinx.coroutines. This implementation is implemented in Kotlin and purely local to the process creating it.

On the web, we also want to guard against multiple tabs attempting to sync at the same time. We should ideally use a shared worker for that like we do on our other SDKs, but we definitely don't want two tabs to sync independently at the same time.

This adds the internal PowerSyncMutex interface providing a subset of Mutex that can be implemented with navigator locks. The implementation for native platforms and the JVM is unchanged. For the web, this uses navigator locks to guard the sync client. This also moves the withAbortSignal utility from :core to :common, as it's helpful for the mutex implementation.

AI use: Implementation manual, reviewed with Claude Code.

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