Skip to content

Commit d43d461

Browse files
Closing the write and the watch stream after 60s of idleness (#275)
1 parent 369b411 commit d43d461

File tree

10 files changed

+346
-112
lines changed

10 files changed

+346
-112
lines changed

packages/firestore/src/api/database.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class Firestore implements firestore.Firestore, FirebaseService {
188188
// Operations on the _firestoreClient don't block on _firestoreReady. Those
189189
// are already set to synchronize on the async queue.
190190
private _firestoreClient: FirestoreClient | undefined;
191+
private _queue = new AsyncQueue();
191192
public _dataConverter: UserDataConverter;
192193

193194
constructor(databaseIdOrApp: FirestoreDatabase | FirebaseApp) {
@@ -310,7 +311,7 @@ export class Firestore implements firestore.Firestore, FirebaseService {
310311
PlatformSupport.getPlatform(),
311312
databaseInfo,
312313
this._config.credentials,
313-
new AsyncQueue()
314+
this._queue
314315
);
315316
return this._firestoreClient.start(persistence);
316317
}
@@ -374,7 +375,9 @@ export class Firestore implements firestore.Firestore, FirebaseService {
374375
},
375376
// Exposed via INTERNAL for use in tests.
376377
disableNetwork: () => this._firestoreClient.disableNetwork(),
377-
enableNetwork: () => this._firestoreClient.enableNetwork()
378+
enableNetwork: () => this._firestoreClient.enableNetwork(),
379+
drainAsyncQueue: (executeDelayedTasks: boolean) =>
380+
this._queue.drain(executeDelayedTasks)
378381
};
379382

380383
collection(pathString: string): firestore.CollectionReference {

packages/firestore/src/local/local_store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,9 @@ export class LocalStore {
582582

583583
/**
584584
* Gets the mutation batch after the passed in batchId in the mutation queue
585-
* or null if empty.
586-
* @param afterBatchId If provided, the batch to search after.
587-
* @returns The next mutation or null if there wasn't one.
585+
* or null if empty.
586+
* @param afterBatchId If provided, the batch to search after.
587+
* @returns The next mutation or null if there wasn't one.
588588
*/
589589
nextMutationBatch(afterBatchId?: BatchId): Promise<MutationBatch | null> {
590590
return this.persistence.runTransaction('Get next mutation batch', txn => {

packages/firestore/src/remote/datastore.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,24 @@ export class Datastore {
5858
private initialBackoffDelay?: number
5959
) {}
6060

61-
public newPersistentWriteStream(
62-
listener: WriteStreamListener
63-
): PersistentWriteStream {
61+
public newPersistentWriteStream(): PersistentWriteStream {
6462
return new PersistentWriteStream(
6563
this.databaseInfo,
6664
this.queue,
6765
this.connection,
6866
this.credentials,
6967
this.serializer,
70-
listener,
7168
this.initialBackoffDelay
7269
);
7370
}
7471

75-
public newPersistentWatchStream(
76-
listener: WatchStreamListener
77-
): PersistentListenStream {
72+
public newPersistentWatchStream(): PersistentListenStream {
7873
return new PersistentListenStream(
7974
this.databaseInfo,
8075
this.queue,
8176
this.connection,
8277
this.credentials,
8378
this.serializer,
84-
listener,
8579
this.initialBackoffDelay
8680
);
8781
}

0 commit comments

Comments
 (0)