local l={}l.__index=l function l.new(c,g)return setmetatable({_connected=true;_signal=c;_fn=g;_next=false},l)end function l.Disconnect(l)assert(l._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",2)l._connected=false if l._signal._handlerListHead==l then l._signal._handlerListHead=l._next else local c=l._signal._handlerListHead while c and c._next~=l do c=c._next end if c then c._next=l._next end end end

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.", 2)
	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
