Example not work - Coroutines and sync http requests (SOLVED)

sorry, my mistake

i’m get it from this post

local function http_request(url, method)
	local co = coroutine.running()
	http.request("http://d.defold.com/stable/info.json", "GET", function(self, id, response)
		print('result is fetched')
		coroutine.resume(co, response)
	end)
	return coroutine.yield()
end

local co = coroutine.create(function()
	print('request is executed')
	local response = http_request("http://d.defold.com/stable/info.json", "GET")
	print('should not be executed before fetched result')
end)

local ok, err = coroutine.resume(co)

why do I need it

global_["host_name"] = {'http://127.0.0.1',  'http://127.0.0.1:2347'}

function load_init_callback(self, _, response)
	pprint(response)
end
	
for key, value in pairs(global_.host_name) do
    http.request(value .. '/?action=' .. global_.init_url, "POST", load_init_callback, global_.header, '')
end

but i cant get the table index for responded server
i have alvays 2 because request is async

1 Like