It is the code within the coroutine that doesn’t continue to execute. In this case as soon as you yield you give back control to the main thread and the print() will be executed.
The correct code would be:
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)