local p = pauser.new(100) # deploy new wait fuction
event:Once(function()
p:destroy() # free the wait function
end)
p:start() # start the wait for 100 seconds
print("Wait free !")
becouse its not.
its just some random OOP-slop as always.
Legit bro the code is a joke:
local pause = {}
pause.__index = pause
export type pauser = {
now:number,
ender:number,
}
function pause.new(duration:number)
local self = setmetatable({}, pause)
self.now = tick()
self.ender = self.now + duration
self.stop = false
return self
end
function pause:start()
repeat task.wait() until (tick() >= self.ender) or self.stop
end
function pause:destroy()
self.stop = true
end
return pause
This module is a nice idea, I see why somebody would want to use this. However, it’s much simpler to use coroutines. They are built-in, and they don’t use polling to see if threads should resume. It’s purpose is to better manage when threads yield and continue running again.
-- Your example:
local p = pauser.new(100) -- deploy new wait fuction
event:Once(function()
p:destroy() -- free the wait function
end)
p:start() -- start the wait for 100 seconds
print("Wait free !")
-- Your example but with threading/coroutines:
local thread = coroutine.running()
task.delay(100, function()
pcall(task.spawn, thread) -- Stop waiting after 100 seconds
end)
event:Once(function()
pcall(task.spawn, thread) -- Stop waiting after event fires
end)
coroutine.yield() -- Start waiting
thread = nil -- Prevents mistakenly spawning again
print "Wait free!"
With threading, the behavior is obvious and can’t be mistaken. The “pauser” module has weird behavior, which will make developers confused. So please, use threading instead!