@JeViCo
The syntax:
bool fetchRemote ( string URL[, string queueName = "default" ][, int connectionAttempts = 10, int connectTimeout = 10000 ], function callbackFunction, [ string postData = "", bool postIsBinary = false, [ arguments... ] ] )
Problem 1
Always be called
The callback function will always be called, even if there is an error.
function myCallback( responseData, errno )
if errno == 0 then
Problem 2
Execution order:
Line: 1
local variable
Line: 2
fetchRemote("http_stuff",
Making a network request.
Line: 6
Line: 7
print(variable) -- nil
-------------------------------------------------------------------------------------------------
---------- Waiting for the network request to be finished ----------
-------------------------------------------------------------------------------------------------
Line: 2
function(resp)
Callback function will be called after a delay. The delay can be long or short, depending on the response. If not response, it will be called eventually with an error.
connectTimeout: Number of milliseconds each connection attempt will take before timing out
https://wiki.multitheftauto.com/wiki/FetchRemote
Line: 3
variable = resp
Line: 4
print(variable) -- OK
Line: 5
end)
Callback functions in combination with the network are always async. The code doesn't wait for these callback functions.