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

function ObservableSubscriptionTable:Observe(key, retrieveInitialValue)
	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

		if retrieveInitialValue then
			retrieveInitialValue(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
