refactor(db/connection): tweak waitForConnection logic

This commit is contained in:
Linden committed 2023-11-28 12:01:55 +11:00
1 parent e4f8c98cc4
commit 0f5f397814
2 files changed
+6 -9

No files matched your search

+3 -9
View File
@@ -1,21 +1,15 @@
import { createPool, Pool, RowDataPacket } from 'mysql2/promise';
import { connectionOptions, mysql_transaction_isolation_level } from '../config';
import { scheduleTick } from '../utils/scheduleTick';
import { sleep } from '../utils/sleep';
export let pool: Pool;
export let isServerConnected = false;
export let dbVersion = '';
export async function waitForConnection() {
if (!isServerConnected) {
return await new Promise<boolean>((resolve) => {
(function wait() {
if (isServerConnected) {
return resolve(true);
}
setTimeout(wait);
})();
});
while (!isServerConnected) {
await sleep(0);
}
}
+3
View File
@@ -0,0 +1,3 @@
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}