local q={}q.__index=q function q.new(w,M)local Q=setmetatable({_conn=M;_event=w,Connected=true},q)return Q end function q.IsConnected(q)if q._conn then return q._conn.Connected end return false end function q.Disconnect(q)if q._conn then q._conn:Disconnect()q._conn=nil end if not q._event then return end q.Connected=false local w=q._event._connections for M,Q in ipairs(w)do if Q==q then w[M]=w[#w]w[#w]=nil break end end q._event=nil end q.Destroy=q.Disconnect
--------------------------------------------------------------
-- Connection

local Connection = {}
Connection.__index = Connection

function Connection.new(event, connection)
	local self = setmetatable({
		_conn = connection,
		_event = event,
		Connected = true,
	}, Connection)
	return self
end

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

function Connection:Disconnect()
	if self._conn then
		self._conn:Disconnect()
		self._conn = nil
	end
	if not self._event then
		return
	end
	self.Connected = false
	local connections = self._event._connections
	for i, c in ipairs(connections) do
		if c == self then
			connections[i] = connections[#connections]
			connections[#connections] = nil
			break
		end
	end
	self._event = nil
end

Connection.Destroy = Connection.Disconnect
