MySQLOO - How do I make connect function return AFTER connection has been established?

I have this function in sql.lua:

returnstr = nil
function sqlconnect()

 connection = mysqloo.connect("localhost","root","cat","db",1234)

 function connection:onConnected()
 returnstr = "Connected!"
 function connection:onConnectionFailed(err)
 returnstr = "Failed!"

return returnstr

When I do

printcat = sqlconnect()

in init.lua, it prints “nil” because the sqlconnect() returns returnstr before the onConnected() hooks are called.

How can I make the sqlconnect() function wait until the connection hooks onConnected or onConnectionFailed are called and after that return?

There is no way of returning from a callback, other than freezing the code and waiting until the mysql request arrives back but that’s stupid.
You will need to process all the information inside the :onOnconnected() callback function.

Ill do that.