function Rx.fromPromise(z)assert(Promise.isPromise(z))return Observable.new(function(y)if z:IsFulfilled()then y:Fire(z:Wait())y:Complete()return nil end local H=Maid.new()local d=true H:GiveTask(function()d=false end)z:Then(function(...)if d then y:Fire(...)y:Complete()end end,function(...)if d then y:Fail(...)y:Complete()end end)return H end)end

function Rx.fromPromise(promise)
	assert(Promise.isPromise(promise))

	return Observable.new(function(sub)
		if promise:IsFulfilled() then
			sub:Fire(promise:Wait())
			sub:Complete()
			return nil
		end

		local maid = Maid.new()

		local pending = true
		maid:GiveTask(function()
			pending = false
		end)

		promise:Then(
			function(...)
				if pending then
					sub:Fire(...)
					sub:Complete()
				end
			end,
			function(...)
				if pending then
					sub:Fail(...)
					sub:Complete()
				end
			end)

		return maid
	end)
end
