@@ -484,6 +484,14 @@ export class RemoteStore implements TargetMetadataProvider {
484
484
}
485
485
}
486
486
487
+ /**
488
+ * Executes `op`. If `op` fails, takes the network offline until `op`
489
+ * succeeds. Returns after the first attempt.
490
+ */
491
+ private executeWithRecovery ( op : ( ) => Promise < void > ) : Promise < void > {
492
+ return op ( ) . catch ( e => this . disableNetworkUntilRecovery ( e , op ) ) ;
493
+ }
494
+
487
495
/**
488
496
* Takes a batch of changes from the Datastore, repackages them as a
489
497
* RemoteEvent, and passes that on to the listener, which is typically the
@@ -678,13 +686,10 @@ export class RemoteStore implements TargetMetadataProvider {
678
686
) ;
679
687
const batch = this . writePipeline . shift ( ) ! ;
680
688
const success = MutationBatchResult . from ( batch , commitVersion , results ) ;
681
- try {
682
- await this . syncEngine . applySuccessfulWrite ( success ) ;
683
- } catch ( e ) {
684
- await this . disableNetworkUntilRecovery ( e , ( ) =>
685
- this . syncEngine . applySuccessfulWrite ( success )
686
- ) ;
687
- }
689
+
690
+ await this . executeWithRecovery ( ( ) =>
691
+ this . syncEngine . applySuccessfulWrite ( success )
692
+ ) ;
688
693
689
694
// It's possible that with the completion of this mutation another
690
695
// slot has freed up.
@@ -728,13 +733,9 @@ export class RemoteStore implements TargetMetadataProvider {
728
733
// restart.
729
734
this . writeStream . inhibitBackoff ( ) ;
730
735
731
- try {
732
- await this . syncEngine . rejectFailedWrite ( batch . batchId , error ) ;
733
- } catch ( e ) {
734
- await this . disableNetworkUntilRecovery ( e , ( ) =>
735
- this . syncEngine . rejectFailedWrite ( batch . batchId , error )
736
- ) ;
737
- }
736
+ await this . executeWithRecovery ( ( ) =>
737
+ this . syncEngine . rejectFailedWrite ( batch . batchId , error )
738
+ ) ;
738
739
739
740
// It's possible that with the completion of this mutation
740
741
// another slot has freed up.
0 commit comments