local w={}w.__index=w function w.new(l)local R=setmetatable({_handlerListHead=false},w)if l then R.totalConnections=0 R.connectionsChanged=w.new()end return R end function w.Connect(l,w)local R=Connection.new(l,w)if l._handlerListHead then R._next=l._handlerListHead l._handlerListHead=R else l._handlerListHead=R end if l.connectionsChanged then l.totalConnections+=1 l.connectionsChanged:Fire(1)end return R end

local Signal = {}
Signal.__index = Signal

function Signal.new(createConnectionsChangedSignal)
	local self = setmetatable({
		_handlerListHead = false,	
	}, Signal)
    if createConnectionsChangedSignal then
        self.totalConnections = 0
		self.connectionsChanged = Signal.new()
	end
    return self
end

function Signal:Connect(fn)
	local connection = Connection.new(self, fn)
	if self._handlerListHead then
		connection._next = self._handlerListHead
		self._handlerListHead = connection
	else
		self._handlerListHead = connection
	end

	if self.connectionsChanged then
        self.totalConnections += 1
		self.connectionsChanged:Fire(1)
	end
	return connection
end
