local q={}q.__index=q function q.new(f,P)return setmetatable({_connected=true;_signal=f,_fn=P,_next=false},q)end function q.Disconnect(q)assert(q._connected,"\067\111\110\110\101\099\116\105\111\110 \097\108\114\101\097\100\121 \100\105\115\099\111\110\110\101\099\116\101\100\046")q._connected=false if q._signal._handlerListHead==q then q._signal._handlerListHead=q._next else local f=q._signal._handlerListHead while f and f._next~=q do f=f._next end if f then f._next=q._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, "Connection already disconnected.")
	self._connected = false

	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
