@@ -294,30 +294,37 @@ protected async Task StreamingSync(CancellationToken? signal, PowerSyncConnectio
294294 } ) ;
295295 } ) ;
296296
297- /// This loops runs until [retry] is false or the abort signal is set to aborted.
298- /// Aborting the nestedCts will:
299- /// - Abort any pending fetch requests
300- /// - Close any sync stream ReadableStreams (which will also close any established network requests)
297+ // This loops runs until [retry] is false or the abort signal is set to aborted.
298+ // Aborting the nestedCts will:
299+ // - Abort any pending fetch requests
300+ // - Close any sync stream ReadableStreams (which will also close any established network requests)
301301 while ( true )
302302 {
303+ Console . WriteLine ( 1 ) ;
303304 UpdateSyncStatus ( new SyncStatusOptions { Connecting = true } ) ;
305+ Console . WriteLine ( 2 ) ;
304306 var iterationResult = ( StreamingSyncIterationResult ? ) null ;
305307 try
306308 {
309+ Console . WriteLine ( 3 ) ;
307310 if ( signal . Value . IsCancellationRequested )
308311 {
312+ Console . WriteLine ( "BREAKINGNNNNG" ) ;
309313 break ;
310314 }
315+ Console . WriteLine ( 4 ) ;
311316 iterationResult = await StreamingSyncIteration ( nestedCts . Token , options ) ;
312- if ( ! iterationResult . Retry . GetValueOrDefault ( false ) )
317+ if ( ! iterationResult . Retry )
313318 {
319+ Console . WriteLine ( 5 ) ;
314320
315321 // A sync error ocurred that we cannot recover from here.
316322 // This loop must terminate.
317323 // The nestedCts will close any open network requests and streams below.
318324 break ;
319325 }
320326 // Continue immediately
327+ Console . WriteLine ( 6 ) ;
321328 }
322329 catch ( Exception ex )
323330 {
@@ -327,9 +334,9 @@ protected async Task StreamingSync(CancellationToken? signal, PowerSyncConnectio
327334 exMessage = "Stream closed or timed out -" + ex . InnerException . Message ;
328335 }
329336
330-
337+ Console . WriteLine ( 7 ) ;
331338 logger . LogError ( "Caught exception in streaming sync: {message}" , exMessage ) ;
332-
339+ Console . WriteLine ( 8 ) ;
333340 // Either:
334341 // - A network request failed with a failed connection or not OKAY response code.
335342 // - There was a sync processing error.
@@ -345,9 +352,14 @@ protected async Task StreamingSync(CancellationToken? signal, PowerSyncConnectio
345352 DownloadError = ex
346353 }
347354 } ) ;
355+
356+ Console . WriteLine ( 9 ) ;
357+ await DelayRetry ( ) ;
358+ Console . WriteLine ( 10 ) ;
348359 }
349360 finally
350361 {
362+ Console . WriteLine ( 11 ) ;
351363 notifyCompletedUploads = null ;
352364
353365 if ( ! signal . Value . IsCancellationRequested )
@@ -358,17 +370,18 @@ protected async Task StreamingSync(CancellationToken? signal, PowerSyncConnectio
358370 }
359371
360372
361- if ( iterationResult != null && iterationResult . ImmediateRestart . GetValueOrDefault ( false ) )
373+ // if (iterationResult != null && iterationResult.ImmediateRestart.GetValueOrDefault(false))
374+ // {
375+ Console . WriteLine ( 12 ) ;
376+ UpdateSyncStatus ( new SyncStatusOptions
362377 {
363- UpdateSyncStatus ( new SyncStatusOptions
364- {
365- Connected = false ,
366- Connecting = true // May be unnecessary
367- } ) ;
378+ Connected = false ,
379+ Connecting = true // May be unnecessary
380+ } ) ;
368381
369- // On error, wait a little before retrying
370- await DelayRetry ( ) ;
371- }
382+ // On error, wait a little before retrying
383+
384+ // }
372385 }
373386 }
374387
@@ -382,7 +395,7 @@ protected async Task StreamingSync(CancellationToken? signal, PowerSyncConnectio
382395
383396 protected record StreamingSyncIterationResult
384397 {
385- public bool ? Retry { get ; init ; }
398+ public bool Retry { get ; init ; }
386399
387400 public bool ? ImmediateRestart { get ; init ; }
388401 }
@@ -956,30 +969,37 @@ protected record UpdateSyncStatusOptions(
956969 ) ;
957970 protected void UpdateSyncStatus ( SyncStatusOptions options , UpdateSyncStatusOptions ? updateOptions = null )
958971 {
959- var updatedStatus = new SyncStatus ( new SyncStatusOptions
972+ try
960973 {
961- Connected = options . Connected ?? SyncStatus . Connected ,
962- Connecting = ! options . Connected . GetValueOrDefault ( ) && ( options . Connecting ?? SyncStatus . Connecting ) ,
963- LastSyncedAt = options . LastSyncedAt ?? SyncStatus . LastSyncedAt ,
964- DataFlow = new SyncDataFlowStatus
974+ var updatedStatus = new SyncStatus ( new SyncStatusOptions
965975 {
966- Uploading = options . DataFlow ? . Uploading ?? SyncStatus . DataFlowStatus . Uploading ,
967- Downloading = options . DataFlow ? . Downloading ?? SyncStatus . DataFlowStatus . Downloading ,
968- DownloadError = updateOptions ? . ClearDownloadError == true ? null : options . DataFlow ? . DownloadError ?? SyncStatus . DataFlowStatus . DownloadError ,
969- UploadError = updateOptions ? . ClearUploadError == true ? null : options . DataFlow ? . UploadError ?? SyncStatus . DataFlowStatus . UploadError ,
976+ Connected = options . Connected ?? SyncStatus . Connected ,
977+ Connecting = ! options . Connected . GetValueOrDefault ( ) && ( options . Connecting ?? SyncStatus . Connecting ) ,
978+ LastSyncedAt = options . LastSyncedAt ?? SyncStatus . LastSyncedAt ,
979+ DataFlow = new SyncDataFlowStatus
980+ {
981+ Uploading = options . DataFlow ? . Uploading ?? SyncStatus . DataFlowStatus . Uploading ,
982+ Downloading = options . DataFlow ? . Downloading ?? SyncStatus . DataFlowStatus . Downloading ,
983+ DownloadError = updateOptions ? . ClearDownloadError == true ? null : options . DataFlow ? . DownloadError ?? SyncStatus . DataFlowStatus . DownloadError ,
984+ UploadError = updateOptions ? . ClearUploadError == true ? null : options . DataFlow ? . UploadError ?? SyncStatus . DataFlowStatus . UploadError ,
985+ }
986+ } ) ;
987+
988+ if ( ! SyncStatus . Equals ( updatedStatus ) )
989+ {
990+ SyncStatus = updatedStatus ;
991+ logger . LogDebug ( "[Sync status updated]: {message}" , updatedStatus . ToJSON ( ) ) ;
992+ // Only trigger this if there was a change
993+ Emit ( new StreamingSyncImplementationEvent { StatusChanged = updatedStatus } ) ;
970994 }
971- } ) ;
972995
973- if ( ! SyncStatus . Equals ( updatedStatus ) )
996+ // Trigger this for all updates
997+ Emit ( new StreamingSyncImplementationEvent { StatusUpdated = options } ) ;
998+ }
999+ catch ( Exception ex )
9741000 {
975- SyncStatus = updatedStatus ;
976- logger . LogDebug ( "[Sync status updated]: {message}" , updatedStatus . ToJSON ( ) ) ;
977- // Only trigger this if there was a change
978- Emit ( new StreamingSyncImplementationEvent { StatusChanged = updatedStatus } ) ;
1001+ logger . LogError ( "Error updating sync status: {message}" , ex . Message ) ;
9791002 }
980-
981- // Trigger this for all updates
982- Emit ( new StreamingSyncImplementationEvent { StatusUpdated = options } ) ;
9831003 }
9841004
9851005 private static DB . Crud . SyncPriorityStatus CoreStatusToSyncStatus ( SyncPriorityStatus status )
0 commit comments