Feedback on my signal module

Hello hello everybody once again :D. Recently ive been experimentin with creating custom events and now i come here asking for feedback on my signal module (:slightly_smiling_face: . Thats basically everything you need to know. Theres nothing more to add

Any feedback on how it could be improved is highly appreciated (:slightly_smiling_face:

Signal code:

local Signal = {}
local Connection = {}



Signal.__index = Signal
Connection.__index = Connection



local function Count(T)
	local Num = 0
	
	for _, v in pairs(T) do
		Num = Num + 1
	end
	return Num
end


function Signal.new()
	return setmetatable({
		
		_Cons = {}
		
		
	},Signal)
end


function Signal:Connect(Callback)
	
	local Index = Count(self._Cons)
	
	local Handler = Connection.new(self._Cons,Index)
	
	self._Cons[Index] = Callback
	
	return Handler
end


function Signal:Fire(...)
	
	for _, v in pairs(self._Cons) do
		
		task.spawn(v,...)
		
	end
	
end




function Connection.new(Location,Key)
	return setmetatable({
		
		_Location = Location,
		_Key = Key,
		
	},Connection)
end


function Connection:Disconnect()
	self._Location[self._Key] = nil
end





return Signal
1 Like