function Rx.fromPromise(y)assert(Promise.isPromise(y))return Observable.new(function(k)if y:IsFulfilled()then k:Fire(y:Wait())k:Complete()return nil end local S=Maid.new()local x=true S:GiveTask(function()x=false end)y:Then(function(...)if x then k:Fire(...)k:Complete()end end,function(...)if x then k:Fail(...)k:Complete()end end)return S end)end
--[=[
	Converts a Promise into an observable.
	https://rxjs-dev.firebaseapp.com/api/index/function/from

	@param promise Promise<T>
	@return Observable<T>
]=]
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
