in src/lib/database.ts [79:102]
async isConnected(timeout: number = 5): Promise<boolean> {
try {
timeout = Math.min(timeout, 60) * 1000;
// eslint-disable-next-line no-undef
let timerId: NodeJS.Timeout;
const timer = new Promise<boolean>((resolve) => {
timerId = setTimeout(() => resolve(false), timeout);
});
// TODO: research if there's a lighter weight way to status a connection.
const connectionCheck = this.db.listCollections();
return Promise.race([connectionCheck, timer]).then(result => {
clearTimeout(timerId);
return !!result;
});
} catch (err) {
// GoogleError: Total timeout of API google.firestore.v1.Firestore
// exceeded 60000 milliseconds before any response was received.
return false;
}
}