(db: Database, upstream: SyncRPC)
| 125 | // kill the daemon. The watermarks are durable, so the next tick |
| 126 | // resumes from where the failed one would have. |
| 127 | function startSyncLoop(db: Database, upstream: SyncRPC): () => void { |
| 128 | let stopped = false; |
| 129 | const handle = setInterval(() => { |
| 130 | if (stopped) return; |
| 131 | tick(db, upstream).catch((error) => { |
| 132 | console.error("sync tick failed:", error); |
| 133 | }); |
| 134 | }, SYNC_TICK_MS); |
| 135 | // Don't block process exit on the timer. computerd's shutdown path |
| 136 | // calls stopSync() explicitly; this is belt-and-braces. |
| 137 | handle.unref?.(); |
| 138 | return () => { |
| 139 | if (stopped) return; |
| 140 | stopped = true; |
| 141 | clearInterval(handle); |
| 142 | }; |
| 143 | } |
no test coverage detected