local M local v={}v.__index=v function v.new(M,s)local k=setmetatable({_signal=M,_conn=s;Connected=true},v)return k end function v.Disconnect(M)if M._conn then M._conn:Disconnect()M._conn=nil end if not M._signal then return end M.Connected=false local v=M._signal._connections local s=table.find(v,M)if s then local M=#v v[s]=v[M]v[M]=nil end M._signal=nil end function v.IsConnected(M)if M._conn then return M._conn.Connected end return false end v.Destroy=v.Disconnect


local Promise

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
