Created
March 5, 2021 03:49
-
-
Save TheEpicFace007/4770750b9f50a6c1b547fe60d7f36de1 to your computer and use it in GitHub Desktop.
lua set interval
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
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