local E={}E.__index=E function E.new(F)local S=setmetatable({_handlerListHead=false,_proxyHandler=nil},E)if F then F:Add(S)end return S end function E.Wrap(F,S)assert(typeof(F)=="\082\066\088\083\099\114\105\112\116\083\105\103\110\097\108","\065\114\103\117\109\101\110\116 \035\049 \116\111 \083\105\103\110\097\108\046\087\114\097\112 \109\117\115\116 \098\101 \097 \082\066\088\083\099\114\105\112\116\083\105\103\110\097\108\059 \103\111\116 "..typeof(F))local Y=E.new(S)Y._proxyHandler=F:Connect(function(...)Y:Fire(...)end)return Y end function E.Is(F)return type(F)=="\116\097\098\108\101"and getmetatable(F)==E end function E.Connect(F,E)local S=Connection.new(F,E)if F._handlerListHead then S._next=F._handlerListHead F._handlerListHead=S else F._handlerListHead=S end return S end function E.GetConnections(E)local F={}local S=E._handlerListHead while S do table.insert(F,S)S=S._next end return F end

local Signal = {}
Signal.__index = Signal


function Signal.new(janitor)
	local self = setmetatable({
		_handlerListHead = false,
		_proxyHandler = nil,
	}, Signal)
	if janitor then
		janitor:Add(self)
	end
	return self
end


function Signal.Wrap(rbxScriptSignal, janitor)
	assert(typeof(rbxScriptSignal) == "RBXScriptSignal", "Argument #1 to Signal.Wrap must be a RBXScriptSignal; got " .. typeof(rbxScriptSignal))
	local signal = Signal.new(janitor)
	signal._proxyHandler = rbxScriptSignal:Connect(function(...)
		signal:Fire(...)
	end)
	return signal
end


function Signal.Is(obj)
	return type(obj) == "table" and getmetatable(obj) == Signal
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
	return connection
end


function Signal:GetConnections()
	local items = {}
	local item = self._handlerListHead
	while item do
		table.insert(items, item)
		item = item._next
	end
	return items
end

