@@ -413,7 +413,7 @@ public void handleSuccessfulWrite(MutationBatchResult mutationBatchResult) {
413
413
// they consistently happen before listen events.
414
414
notifyUser (mutationBatchResult .getBatch ().getBatchId (), /*status=*/ null );
415
415
416
- resolveTasksAwaitingForPendingWritesIfAny (mutationBatchResult .getBatch ().getBatchId ());
416
+ resolvePendingWriteTasks (mutationBatchResult .getBatch ().getBatchId ());
417
417
418
418
ImmutableSortedMap <DocumentKey , MaybeDocument > changes =
419
419
localStore .acknowledgeBatch (mutationBatchResult );
@@ -435,16 +435,22 @@ public void handleRejectedWrite(int batchId, Status status) {
435
435
// they consistently happen before listen events.
436
436
notifyUser (batchId , status );
437
437
438
- resolveTasksAwaitingForPendingWritesIfAny (batchId );
438
+ resolvePendingWriteTasks (batchId );
439
439
440
440
emitNewSnapsAndNotifyLocalStore (changes , /*remoteEvent=*/ null );
441
441
}
442
442
443
443
/**
444
- * Takes a snapshot of current local mutation queue, and register a user task which will resolve
445
- * when all those mutations are either accepted or rejected by the server.
444
+ * Takes a snapshot of current mutation queue, and register a user task which will resolve when
445
+ * all those mutations are either accepted or rejected by the server.
446
446
*/
447
447
public void registerPendingWritesTask (TaskCompletionSource <Void > userTask ) {
448
+ if (!remoteStore .canUseNetwork ()) {
449
+ Logger .debug (
450
+ TAG ,
451
+ "The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled." );
452
+ }
453
+
448
454
int largestPendingBatchId = localStore .getHighestUnacknowledgedBatchId ();
449
455
450
456
if (largestPendingBatchId == 0 ) {
@@ -461,7 +467,7 @@ public void registerPendingWritesTask(TaskCompletionSource<Void> userTask) {
461
467
}
462
468
463
469
/** Resolves tasks waiting for this batch id to get acknowledged by server, if there is any. */
464
- private void resolveTasksAwaitingForPendingWritesIfAny (int batchId ) {
470
+ private void resolvePendingWriteTasks (int batchId ) {
465
471
if (pendingWritesCallbacks .containsKey (batchId )) {
466
472
for (TaskCompletionSource <Void > task : pendingWritesCallbacks .get (batchId )) {
467
473
task .setResult (null );
0 commit comments