fix(execute): check resourcestate is 'started' to resolve promise

This commit is contained in:
Linden committed 2021-12-10 10:55:27 +00:00
1 parent 78ce45f1de
commit 4e29905179
2 files changed
+9 -7

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ game 'common'
name 'oxmysql' name 'oxmysql'
description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.' description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.'
version '1.8.6' version '1.8.7'
url 'https://github.com/overextended/oxmysql' url 'https://github.com/overextended/oxmysql'
author 'overextended' author 'overextended'
use_fxv2_oal 'yes' use_fxv2_oal 'yes'
+8 -6
View File
@@ -5,18 +5,20 @@ import { FormatError } from './errors';
let isReady = false; let isReady = false;
const serverReady = () => { const serverReady = async () => {
return new Promise(() => { return new Promise((resolve) => {
setTimeout(() => { const id = setInterval(() => {
return true; if (GetResourceState(resourceName) == 'started') resolve(id);
}); }, 50);
}).then((id) => {
clearInterval(id);
isReady = true;
}); });
}; };
setImmediate(async () => { setImmediate(async () => {
try { try {
await pool.query(isolationLevel); await pool.query(isolationLevel);
isReady = true;
console.log(`^2Database server connection established!^0`); console.log(`^2Database server connection established!^0`);
} catch (error) { } catch (error) {
console.log(`^3Unable to establish a connection to the database! [${error.code}]\n${error.message}^0`); console.log(`^3Unable to establish a connection to the database! [${error.code}]\n${error.message}^0`);