Skip to content

Instantly share code, notes, and snippets.

@TheEpicFace007
Created March 5, 2021 03:49
Show Gist options
  • Save TheEpicFace007/4770750b9f50a6c1b547fe60d7f36de1 to your computer and use it in GitHub Desktop.
Save TheEpicFace007/4770750b9f50a6c1b547fe60d7f36de1 to your computer and use it in GitHub Desktop.
lua set interval
local thread = {}
thread.__index = {}
function thread.new(callback, timeout)
local self = setmetatable({}, thread)
self.running = false
self.callback = callback
self.timeout = timeout
return self
end
function thread:run()
local runner = coroutine.create(function()
while self.running do
self.callback()
wait(self.timeout / 1000)
end
end)
coroutine.resume(runner)
return runner
end
function thread:stop()
self.running = false
coroutine.yield()
end
local myThread = t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment