local H={}H.__index=H function H.new(y,N)local l=setmetatable({_signal=y,_conn=N,Connected=true},H)return l end function H.Disconnect(H)if H._conn then H._conn:Disconnect()H._conn=nil end if not H._signal then return end H.Connected=false local y=H._signal._connections local N=table.find(y,H)if N then local H=#y y[N]=y[H]y[H]=nil end H._signal=nil end function H.IsConnected(H)if H._conn then return H._conn.Connected end return false end H.Destroy=H.Disconnect


local Connection = {}
Connection.__index = Connection

function Connection.new(signal, connection)
	local self = setmetatable({
		_signal = signal;
		_conn = connection;
		Connected = true;
	}, Connection)
	return self
end

function Connection:Disconnect()
	if (self._conn) then
		self._conn:Disconnect()
		self._conn = nil
	end
	if (not self._signal) then return end
	self.Connected = false
	local connections = self._signal._connections
	local connectionIndex = table.find(connections, self)
	if (connectionIndex) then
		local n = #connections
		connections[connectionIndex] = connections[n]
		connections[n] = nil
	end
	self._signal = nil
end

function Connection:IsConnected()
	if (self._conn) then
		return self._conn.Connected
	end
	return false
end

Connection.Destroy = Connection.Disconnect
