local m={}m.__index=m function m.new(S,P)local j=setmetatable({_signal=S;_conn=P,Connected=true},m)return j end function m.Disconnect(m)if m._conn then m._conn:Disconnect()m._conn=nil end if not m._signal then return end m.Connected=false local S=m._signal._connections local P=table.find(S,m)if P then local m=#S S[P]=S[m]S[m]=nil end m._signal=nil end function m.IsConnected(m)if m._conn then return m._conn.Connected end return false end m.Destroy=m.Disconnect
--[[
	signal = Signal.new()
	signal:Fire(...)
	signal:Wait()
	signal:Destroy()
	signal:DisconnectAll()
	
	connection = signal:Connect(functionHandler)
	connection.Connected
	connection:Disconnect()
	connection:IsConnected()
--]]

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
