mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-04 14:38:50 +00:00
refactor(db/connection): tweak waitForConnection logic
This commit is contained in:
1 parent
e4f8c98cc4
commit
0f5f397814
2 files changed
+6
-9
No files matched your search
@@ -1,21 +1,15 @@
|
|||||||
import { createPool, Pool, RowDataPacket } from 'mysql2/promise';
|
import { createPool, Pool, RowDataPacket } from 'mysql2/promise';
|
||||||
import { connectionOptions, mysql_transaction_isolation_level } from '../config';
|
import { connectionOptions, mysql_transaction_isolation_level } from '../config';
|
||||||
import { scheduleTick } from '../utils/scheduleTick';
|
import { scheduleTick } from '../utils/scheduleTick';
|
||||||
|
import { sleep } from '../utils/sleep';
|
||||||
|
|
||||||
export let pool: Pool;
|
export let pool: Pool;
|
||||||
export let isServerConnected = false;
|
export let isServerConnected = false;
|
||||||
export let dbVersion = '';
|
export let dbVersion = '';
|
||||||
|
|
||||||
export async function waitForConnection() {
|
export async function waitForConnection() {
|
||||||
if (!isServerConnected) {
|
while (!isServerConnected) {
|
||||||
return await new Promise<boolean>((resolve) => {
|
await sleep(0);
|
||||||
(function wait() {
|
|
||||||
if (isServerConnected) {
|
|
||||||
return resolve(true);
|
|
||||||
}
|
|
||||||
setTimeout(wait);
|
|
||||||
})();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export function sleep(ms: number) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
Reference in new issue
Block a user