function ObservableSubscriptionTable.Observe(X,e)assert(e~=nil,"\066\097\100 \107\101\121")return Observable.new(function(y)if not X._subMap[e]then X._subMap[e]={y}else table.insert(X._subMap[e],y)end return function()if not X._subMap[e]then return end local j=X._subMap[e]local Z=table.find(j,y)if not Z then return end table.remove(j,Z)if#j==0 then X._subMap[e]=nil end if y:IsPending()then task.spawn(function()y:Complete()end)end end end)end

function ObservableSubscriptionTable:Observe(key)
	assert(key ~= nil, "Bad key")

	return Observable.new(function(sub)
		if not self._subMap[key] then
			self._subMap[key] = { sub }
		else
			table.insert(self._subMap[key], sub)
		end

		return function()
			if not self._subMap[key] then
				return
			end

			local current = self._subMap[key]
			local index = table.find(current, sub)
			if not index then
				return
			end

			table.remove(current, index)
			if #current == 0 then
				self._subMap[key] = nil
			end

			-- Complete the subscription
			if sub:IsPending() then
				task.spawn(function()
					sub:Complete()
				end)
			end
		end
	end)
end
