local t={}t.__index=t function t.new(P,W)local Y=setmetatable({_conn=W,_event=P,Connected=true},t)return Y end function t.IsConnected(t)if t._conn then return t._conn.Connected end return false end function t.Disconnect(t)if t._conn then t._conn:Disconnect()t._conn=nil end if not t._event then return end t.Connected=false local P=t._event._connections for W,Y in ipairs(P)do if Y==t then P[W]=P[#P]P[#P]=nil break end end t._event=nil end t.Destroy=t.Disconnect


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
