Last active
June 7, 2020 15:01
-
-
Save wyozi/de4620ebc343236193a31910fad67bfd to your computer and use it in GitHub Desktop.
Tiny GarrysMod coroutine functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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