Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Author(s): Nettoork#0000
- ]]--
- do
- local coroutines = {}
- avl = function()
- local toRemove = {}
- for i, v in next, coroutines do
- if not v[2] or v[2] < os.time() then
- if (coroutine.status(v[1]) == 'dead') then
- toRemove[#toRemove+1] = i
- else
- local s, timerV = coroutine.resume(v[1])
- v[2] = timerV
- end
- end
- end
- if (toRemove[1]) then
- for i, v in next, toRemove do
- coroutines[v] = nil
- end
- end
- end
- timer = function(f)
- local pauseList = nil
- coroutines[#coroutines + 1] = {coroutine.create(function()
- local pause = function(n)
- coroutine.yield(os.time() + math.floor(n/500)*500)
- end
- f(pause)
- end), timeValue = nil}
- end
- end
- eventLoop = avl
- --[[ Example
- timer(function(sleep)
- for i = 1, 10 do
- print(i)
- sleep(1000)
- end
- end)
- timer(function(sleep)
- for i = 1, 20 do
- print('Hello World!')
- sleep(500)
- end
- end)
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement