Feedback on my first module - nSignal

Hello People, I would like feedbacks on my first ever module

It’s called nSignal, you can download it here
Or you can view the source code:

local nSignal = {}
nSignal.__index = nSignal
nSignal._connections = {}
nSignal._wait = {}

local function Fire(self, ...)
	local threads = {}

	for _, func in ipairs(self._connections) do
		table.insert(threads, coroutine.create(func))
	end

	for _, thread in ipairs(threads) do
		coroutine.resume(thread, ...)
	end

	threads = nil

	for signalWait, _ in pairs(self._wait) do
		self._wait[signalWait] = {...}
	end
	
	task.wait(0.05)
	
	self._wait = {}
end

function nSignal.new()
	local signal = {}
	setmetatable(signal, nSignal)
	
	local function FireWithSignal(...)
		Fire(signal, ...)
	end
	
	return signal, FireWithSignal
end

function nSignal:Connect(func)
	table.insert(self._connections, func)
end

function nSignal:Wait()
	local key = #self._wait + 1
	self._wait[key] = false
	
	repeat task.wait() until self._wait[key] ~= false
	
	return unpack(self._wait[key])
end

function nSignal:ConnectOnce(func)
	table.insert(self._connections, func)
	
	self:Wait()
	
	table.remove(self._connections, table.find(self._connections, func))
end

return nSignal

The question is what does it do and any screenshots?

I reccomend to look at the other works in #resources:community-resources and see how they are formated.

Sorry it was my first community ressource post :sweat_smile:,

I made it because i couldn’t find the signal module made by @Quenty
It’s supposed to do the same thing but has less features.

1 Like

For reference here is my copy of signal! It’s good to try to implement your own stuff too!

1 Like