File tree Expand file tree Collapse file tree 5 files changed +28
-20
lines changed Expand file tree Collapse file tree 5 files changed +28
-20
lines changed Original file line number Diff line number Diff line change @@ -124,3 +124,15 @@ export async function removeFirestoreClient(
124
124
) ;
125
125
}
126
126
}
127
+
128
+ /**
129
+ * Removes all components associated with the provided instance. Must be called
130
+ * when the Firestore instance is terminated.
131
+ */
132
+ export async function removeComponents ( firestore : Firestore ) : Promise < void > {
133
+ const firestoreClientPromise = firestoreClientInstances . get ( firestore ) ;
134
+ if ( firestoreClientPromise ) {
135
+ firestoreClientInstances . delete ( firestore ) ;
136
+ return ( await firestoreClientPromise ) . terminate ( ) ;
137
+ }
138
+ }
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ import {
41
41
import {
42
42
getFirestoreClient ,
43
43
initializeFirestoreClient ,
44
- removeFirestoreClient
44
+ removeComponents
45
45
} from './components' ;
46
46
47
47
/**
@@ -71,7 +71,7 @@ export class Firestore extends LiteFirestore
71
71
72
72
async _terminate ( ) : Promise < void > {
73
73
await super . _terminate ( ) ;
74
- await removeFirestoreClient ( this ) ;
74
+ await removeComponents ( this ) ;
75
75
}
76
76
}
77
77
Original file line number Diff line number Diff line change 15
15
* limitations under the License.
16
16
*/
17
17
18
- import {
19
- Datastore ,
20
- newDatastore ,
21
- terminateDatastore
22
- } from '../../../src/remote/datastore' ;
18
+ import { Datastore , newDatastore } from '../../../src/remote/datastore' ;
23
19
import { newConnection } from '../../../src/platform/connection' ;
24
20
import { newSerializer } from '../../../src/platform/serializer' ;
25
21
import { Firestore } from './database' ;
@@ -66,13 +62,13 @@ export function getDatastore(firestore: Firestore): Promise<Datastore> {
66
62
}
67
63
68
64
/**
69
- * Removes and terminates the Datastore for the given instance if it has
70
- * been started .
65
+ * Removes all components associated with the provided instance. Must be called
66
+ * when the Firestore instance is terminated .
71
67
*/
72
- export async function removeDatastore ( firestore : Firestore ) : Promise < void > {
73
- const datastore = await datastoreInstances . get ( firestore ) ;
74
- if ( datastore ) {
68
+ export async function removeComponents ( firestore : Firestore ) : Promise < void > {
69
+ const datastorePromise = await datastoreInstances . get ( firestore ) ;
70
+ if ( datastorePromise ) {
75
71
datastoreInstances . delete ( firestore ) ;
76
- return terminateDatastore ( datastore ) ;
72
+ return ( await datastorePromise ) . termiate ( ) ;
77
73
}
78
74
}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import {
29
29
FirebaseCredentialsProvider
30
30
} from '../../../src/api/credentials' ;
31
31
import { cast } from './util' ;
32
- import { removeDatastore } from './components' ;
32
+ import { removeComponents } from './components' ;
33
33
import { debugAssert } from '../../../src/util/assert' ;
34
34
35
35
/**
@@ -112,7 +112,7 @@ export class Firestore
112
112
*/
113
113
protected _terminate ( ) : Promise < void > {
114
114
debugAssert ( ! this . _terminated , 'Cannot invoke _terminate() more than once' ) ;
115
- return removeDatastore ( this ) ;
115
+ return removeComponents ( this ) ;
116
116
}
117
117
118
118
// TODO(firestoreexp): `deleteApp()` should call the delete method above,
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ import { Query } from '../core/query';
48
48
*/
49
49
export abstract class Datastore {
50
50
abstract start ( connection : Connection ) : void ;
51
+ abstract termiate ( ) : Promise < void > ;
51
52
}
52
53
53
54
/**
@@ -118,6 +119,10 @@ class DatastoreImpl extends Datastore {
118
119
throw error ;
119
120
} ) ;
120
121
}
122
+
123
+ async termiate ( ) : Promise < void > {
124
+ this . terminated = false ;
125
+ }
121
126
}
122
127
123
128
// TODO(firestorexp): Make sure there is only one Datastore instance per
@@ -230,8 +235,3 @@ export function newPersistentWatchStream(
230
235
listener
231
236
) ;
232
237
}
233
-
234
- export function terminateDatastore ( datastore : Datastore ) : void {
235
- const datastoreImpl = debugCast ( datastore , DatastoreImpl ) ;
236
- datastoreImpl . terminated = true ;
237
- }
You can’t perform that action at this time.
0 commit comments