Pauser | a wait function but better

A small OOP easy made for convenience use as a wait function

  • Easy to edit and add stuff into it,
  • You stop the wait immedialy

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 !")

: Get This Module

Why should this be used over task.wait and task.delay?

1 Like

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

task.delay but worse.

Damn, dont need to be so harsh

1 Like

anything but use task.delay i guess

Damn, you don’t gotta be so hard on bro :sob:

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!

1 Like

I’m not harsh.
If truth hurts you, then you are wrong.

There is nothing wrong at saying truth

anything but coroutines these days

1 Like

I mean task library is kinda OP.
It cuts ammount of bytecode instructions needed to initiate a thread.