Wrap Sync exports in CreateThread/setImmediate

This commit is contained in:
Linden committed 2021-10-25 08:09:00 +11:00
1 parent 9af6205bb7
commit 2c2f4e0661
5 files changed
+59 -39

No files matched your search

+15 -11
View File
@@ -18,12 +18,14 @@ When selecting data it will return all matching rows and columns, otherwise it w
```
**Sync**
```lua
local result = exports.oxmysql:executeSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
if result then
for _, v in pairs(result) do
print(v.identifier, v.firstname, v.lastname)
CreateThread(function()
local result = exports.oxmysql:executeSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
if result then
for _, v in pairs(result) do
print(v.identifier, v.firstname, v.lastname)
end
end
end
end)
```
=== "JavaScript"
**Async**
@@ -38,10 +40,12 @@ When selecting data it will return all matching rows and columns, otherwise it w
```
**Sync**
```js
const result = await exports.oxmysql.executeSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
if (result) {
result.forEach((v) => {
console.log(v.identifier, v.firstname, v.lastname)
})
}
setImmediate(async () => {
const result = await exports.oxmysql.executeSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
if (result) {
result.forEach((v) => {
console.log(v.identifier, v.firstname, v.lastname)
})
}
})
```