local M={}M.__index=M function M.new(V,h)return setmetatable({_connected=true,_signal=V,_fn=h;_next=false},M)end function M.Disconnect(M)assert(M._connected,"\067\097\110\'\116 \100\105\115\099\111\110\110\101\099\116 \097 \099\111\110\110\101\099\116\105\111\110 \116\119\105\099\101\046")M._connected=false if M._signal._handlerListHead==M then M._signal._handlerListHead=M._next else local V=M._signal._handlerListHead while V and V._next~=M do V=V._next end if V then V._next=M._next end end end
-- Connection class
local Connection = {}
Connection.__index = Connection

function Connection.new(signal, fn)
	return setmetatable({
		_connected = true,
		_signal = signal,
		_fn = fn,
		_next = false,
	}, Connection)
end

function Connection:Disconnect()
	assert(self._connected, "Can't disconnect a connection twice.")
	self._connected = false

	-- Unhook the node, but DON'T clear it. That way any fire calls that are
	-- currently sitting on this node will be able to iterate forwards off of
	-- it, but any subsequent fire calls will not hit it, and it will be GCed
	-- when no more fire calls are sitting on it.
	if self._signal._handlerListHead == self then
		self._signal._handlerListHead = self._next
	else
		local prev = self._signal._handlerListHead
		while prev and prev._next ~= self do
			prev = prev._next
		end
		if prev then
			prev._next = self._next
		end
	end
end
