function RxBrioUtils.toEmitOnDeathObservable(M,l)if not Brio.isBrio(M)then return Rx.of(M)else return Observable.new(function(v)if M:IsDead()then v:Fire(l)v:Complete()else v:Fire(M:GetValue())if not v:IsPending()then return end if M:IsDead()then v:Fire(l)v:Complete()else return(M:GetDiedSignal()):Connect(function()v:Fire(l)v:Complete()end)end end end)end end

function RxBrioUtils.toEmitOnDeathObservable(brio, emitOnDeathValue)
	if not Brio.isBrio(brio) then
		return Rx.of(brio)
	else
		return Observable.new(function(sub)
			if brio:IsDead() then
				sub:Fire(emitOnDeathValue)
				sub:Complete()
			else
				sub:Fire(brio:GetValue())

				-- Firing killed the subscription
				if not sub:IsPending() then
					return
				end

				-- Firing this event actually killed the brio
				if brio:IsDead() then
					sub:Fire(emitOnDeathValue)
					sub:Complete()
				else
					return brio:GetDiedSignal():Connect(function()
						sub:Fire(emitOnDeathValue)
						sub:Complete()
					end)
				end
			end
		end)
	end
end
