Skip to content

Instantly share code, notes, and snippets.

@wyozi
Last active June 7, 2020 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wyozi/de4620ebc343236193a31910fad67bfd to your computer and use it in GitHub Desktop.
Save wyozi/de4620ebc343236193a31910fad67bfd to your computer and use it in GitHub Desktop.
Tiny GarrysMod coroutine functions
function cofetch(url, headers)
local co = coroutine.running()
assert(co)
-- ensure we wait at least one tick
timer.Simple(0, function()
http.Fetch(url, function(body, size, headers, code)
coroutine.resume(co, body, size, headers, code)
end, function(err)
coroutine.resume(false, err)
end, headers)
end)
return coroutine.yield()
end
function cosleep(secs)
local co = coroutine.running()
assert(co)
timer.Simple(secs, function()
coroutine.resume(co)
end)
coroutine.yield()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment