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

1 Like

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

3 Likes

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.

5 Likes

Damn, dont need to be so harsh

6 Likes

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!

5 Likes

There is nothing wrong at saying truth

anything but coroutines these days

4 Likes

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

2 Likes

I did not know task was more efficient, I just use it because it’s faster to type than coroutine lol

You call one function instead of many to setup coroutine.
so it makes sense to be faster.

1 Like

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 !

1 Like

there’s… no point in this… it’s just… a one line… thing… but… calls… __index, repetead tick()… and few other checks…

and… it… becomes… unuseful… after… ending… don’t… use… it… it… destroys… perfomance… and.. is… horrible…

if… you.. want… this type… of… things… then… use… RunService… not… built-in… functions… or use… tick system…

(sorry if it seems harsh or rude.)

Also, what is the point of this…
image

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 :sob:

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

5 Likes

Exactly!
Code is not a toy!
You need to get thing working instead of “It looking swag”

1 Like

it will look swaggy when it is done

i wouldn’t know (i never finish projects)

3 Likes

i like this a lot personally
you can put loading messages
its pretty helpful for a loading screen