Skip to content

Commit 2674016

Browse files
Undo async
1 parent 49bde61 commit 2674016

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

packages/firestore/exp/src/api/components.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,41 +144,43 @@ function verifyNotTerminated(firestore: Firestore): void {
144144
}
145145
}
146146

147-
export async function getSyncEngine(firestore: Firestore): Promise<SyncEngine> {
148-
const components = await getOnlineComponentProvider(firestore);
149-
return components.syncEngine;
150-
}
147+
// Note: These functions cannot be `async` since we want to throw an exception
148+
// when Firestore is terminated (via `getOnlineComponentProvider()`).
151149

152-
export async function getRemoteStore(
153-
firestore: Firestore
154-
): Promise<RemoteStore> {
155-
const components = await getOnlineComponentProvider(firestore);
156-
return components.remoteStore;
150+
export function getSyncEngine(firestore: Firestore): Promise<SyncEngine> {
151+
return getOnlineComponentProvider(firestore).then(
152+
components => components.syncEngine
153+
);
157154
}
158155

159-
export async function getEventManager(
160-
firestore: Firestore
161-
): Promise<EventManager> {
162-
const components = await getOnlineComponentProvider(firestore);
163-
const eventManager = components.eventManager;
164-
eventManager.onListen = syncEngineListen.bind(null, components.syncEngine);
165-
eventManager.onUnlisten = syncEngineUnlisten.bind(
166-
null,
167-
components.syncEngine
156+
export function getRemoteStore(firestore: Firestore): Promise<RemoteStore> {
157+
return getOnlineComponentProvider(firestore).then(
158+
components => components.remoteStore
168159
);
169-
return eventManager;
170160
}
171161

172-
export async function getPersistence(
173-
firestore: Firestore
174-
): Promise<Persistence> {
175-
const components = await getOfflineComponentProvider(firestore);
176-
return components.persistence;
162+
export function getEventManager(firestore: Firestore): Promise<EventManager> {
163+
return getOnlineComponentProvider(firestore).then(components => {
164+
const eventManager = components.eventManager;
165+
eventManager.onListen = syncEngineListen.bind(null, components.syncEngine);
166+
eventManager.onUnlisten = syncEngineUnlisten.bind(
167+
null,
168+
components.syncEngine
169+
);
170+
return eventManager;
171+
});
177172
}
178173

179-
export async function getLocalStore(firestore: Firestore): Promise<LocalStore> {
180-
const components = await getOfflineComponentProvider(firestore);
181-
return components.localStore;
174+
export function getPersistence(firestore: Firestore): Promise<Persistence> {
175+
return getOfflineComponentProvider(firestore).then(
176+
components => components.persistence
177+
);
178+
}
179+
180+
export function getLocalStore(firestore: Firestore): Promise<LocalStore> {
181+
return getOfflineComponentProvider(firestore).then(
182+
provider => provider.localStore
183+
);
182184
}
183185

184186
/**

0 commit comments

Comments
 (0)