local X={}X.__index=X function X.new(F,e)return setmetatable({_connected=true;_signal=F,_fn=e,_next=false},X)end function X.Disconnect(X)X._connected=false if X._signal._handlerListHead==X then X._signal._handlerListHead=X._next else local F=X._signal._handlerListHead while F and F._next~=X do F=F._next end if F then F._next=X._next end end end X.Destroy=X.Disconnect

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()
	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

Connection.Destroy = Connection.Disconnect
