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!
yo it’s me, I’m sorry of how I show my stupidity in that code
I’m very new to framework making, so I use this for my own game for how I design stuff
thankque for the feedback and if there is something I can study more, please recommended
I would be thankfully and study my mistake !
Unrelated to the topic but i think alot of new people now have completely forgot the purpose of : for functions and just use it for everything
Like i see people using : for functions that don’t even need to use self, they say “it looks nicer” but bro just use .!!! It also allows you to declare your table functions as local vars without having to pass a redundant parameter which is a huge w