From 4e29905179698cac1a9fc5c6f9b6850c5ad75399 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Fri, 10 Dec 2021 10:55:27 +0000 Subject: [PATCH] fix(execute): check resourcestate is 'started' to resolve promise --- lua/fxmanifest.lua | 2 +- src/execute.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lua/fxmanifest.lua b/lua/fxmanifest.lua index ffb89f8..26c9f83 100644 --- a/lua/fxmanifest.lua +++ b/lua/fxmanifest.lua @@ -3,7 +3,7 @@ game 'common' name 'oxmysql' 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' author 'overextended' use_fxv2_oal 'yes' diff --git a/src/execute.js b/src/execute.js index c984562..1b3487b 100644 --- a/src/execute.js +++ b/src/execute.js @@ -5,18 +5,20 @@ import { FormatError } from './errors'; let isReady = false; -const serverReady = () => { - return new Promise(() => { - setTimeout(() => { - return true; - }); +const serverReady = async () => { + return new Promise((resolve) => { + const id = setInterval(() => { + if (GetResourceState(resourceName) == 'started') resolve(id); + }, 50); + }).then((id) => { + clearInterval(id); + isReady = true; }); }; setImmediate(async () => { try { await pool.query(isolationLevel); - isReady = true; console.log(`^2Database server connection established!^0`); } catch (error) { console.log(`^3Unable to establish a connection to the database! [${error.code}]\n${error.message}^0`);