MCPcopy Create free account
hub / github.com/electric-sql/electric / waitForInitialSyncDone

Function waitForInitialSyncDone

examples/linearlite/src/sync.ts:290–320  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

288let initialSyncDone = false
289
290export function waitForInitialSyncDone() {
291 return new Promise<void>((resolve) => {
292 if (initialSyncDone) {
293 resolve()
294 return
295 }
296 const handleStorageChange = (e: StorageEvent) => {
297 if (e.key === `syncStatus` && e.newValue) {
298 const [newStatus] = JSON.parse(e.newValue)
299 if (newStatus === `done`) {
300 window.removeEventListener(`storage`, handleStorageChange)
301 initialSyncDone = true
302 resolve()
303 }
304 }
305 }
306
307 // Check current status first
308 const currentSyncStatusJson = localStorage.getItem(`syncStatus`)
309 const [currentStatus] = currentSyncStatusJson
310 ? JSON.parse(currentSyncStatusJson)
311 : [`initial-sync`]
312
313 if (currentStatus === `done`) {
314 initialSyncDone = true
315 resolve()
316 } else {
317 window.addEventListener(`storage`, handleStorageChange)
318 }
319 })
320}

Callers 3

issueListLoaderFunction · 0.90
boardIssueListLoaderFunction · 0.90
issueLoaderFunction · 0.90

Calls 3

resolveFunction · 0.85
getItemMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected