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