[HELP] my function no return result

hello I have created a function to retrieve the info of the player but it does not return any result outside the function, if I call a print in the function its works, but I want to recover the result outside the function

ps :sry for my bad english

function getPlayerInfo(id)
	local player = getIdentifier(id)

	MySQL.Async.fetchAll('SELECT * FROM users WHERE identifier = @identifier', {['@identifier'] = tostring(player)}, function(result)
		if result[1] ~= nil then
			return result
		else
			createUser(id)
			return nil
		end
	end)
end)

Because you are returning it to the nested function (the callback) that you pass in the async fetch all arguments.

I’ve ran into a similair problem, i’ve solved it by using an self writting asynchronous wrapper that will store all the results into a table and tell the system to continue if the piece of data is contained inside the table.

You can use the following library to achieve the same:

very thanks for you reply im resolve this problem with use sync request im added you librairy in my favorite for after

ps: promise include in new version mysql async ?
[Release] MySQL Async Library - 3.3.1

local p = MySQL.Async.fetchScalar("SELECT 1")
p:next(function (result)
    print(result)

    return "test"
end):next(function (result)
    print(result)

    error 'An error'
end):next(nil, function(err)
    print(err)

    return ""
end)

-- Synchronisation
promise.all({
    MySQL.Async.execute('SELECT SLEEP(1)'),
    MySQL.Async.fetchScalar('SELECT "test"'),
}):next(function (results)
    print(json.encode(results))
end)

Thats also a thing yes, the developer of mysql-async added promises the the scheduler. Props to him for doing so :smiley:

Totally forgot about that

1 Like