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