@@ -21,11 +21,11 @@ export async function executeBackgroundSync(
2121 try {
2222 logger . info ( '📲 Starting background sync...' ) ;
2323
24- // Open database connection
24+ /** OPEN DATABASE */
2525 db = await createDatabase ( config . databaseName , 'write' ) ;
2626 logger . info ( '✅ Database connection opened' ) ;
2727
28- // Initialize sync extension
28+ /** INITIALIZE SYNC EXTENSION */
2929 await initializeSyncExtension (
3030 db ,
3131 {
@@ -37,7 +37,7 @@ export async function executeBackgroundSync(
3737 logger
3838 ) ;
3939
40- // Set up updateHook to capture changes during sync
40+ /** REGISTER UPDATE HOOK */
4141 const callback = getBackgroundSyncCallback ( ) ;
4242 if ( callback ) {
4343 db . updateHook ( ( { operation, table, rowId } ) => {
@@ -50,6 +50,7 @@ export async function executeBackgroundSync(
5050 logger . info ( '📲 Update hook registered for change tracking' ) ;
5151 }
5252
53+ /** EXECUTE SYNC */
5354 await executeSync ( db , logger , {
5455 useNativeRetry : true ,
5556 maxAttempts : 3 ,
@@ -58,7 +59,7 @@ export async function executeBackgroundSync(
5859
5960 logger . info ( '✅ Background sync completed successfully' ) ;
6061
61- // Call the callback with changes (before closing db so callback can query)
62+ /** INVOKE USER CALLBACK */
6263 if ( callback && db ) {
6364 logger . info (
6465 `📲 Calling background sync callback with ${ changes . length } changes`
@@ -76,10 +77,9 @@ export async function executeBackgroundSync(
7677 logger . error ( '❌ Background sync failed:' , error ) ;
7778 throw error ;
7879 } finally {
79- // Always close database connection
80+ /** CLEANUP */
8081 if ( db ) {
8182 try {
82- // Ensure hook is removed
8383 db . updateHook ( null ) ;
8484 db . close ( ) ;
8585 logger . info ( '✅ Database connection closed' ) ;
0 commit comments