local v=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local E=v("\080\114\111\109\105\115\101")local F=v("\102\097\115\116\083\112\097\119\110")local N={}function N.PromiseRootPart(v)local N=E.new()if v.RootPart then N:Resolve(v.RootPart)return N end F(function()local E=v.RootPart while not E and N:IsPending()do wait(.05)E=v.RootPart end if E and N:IsPending()then N:Resolve(E)end end)return N end return N
--- Utility for Roblox character objects that involve promises.
-- @see Promise
-- @module CharacterPromiseUtil
-- @author Quenty

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local Promise = require("Promise")
local fastSpawn = require("fastSpawn")

local lib = {}

--- Given a humanoid creates a promise that will resolve once the `Humanoid.RootPart` property
-- resolves properly.
-- @param humanoid The humanoid to resolve for the root part
function lib.PromiseRootPart(humanoid)
	local promise = Promise.new()

	if humanoid.RootPart then
		promise:Resolve(humanoid.RootPart)
		return promise
	end

	-- humanoid:GetPropertyChangedSignal("RootPart") does not fire
	fastSpawn(function()
		local rootPart = humanoid.RootPart
		while not rootPart and promise:IsPending() do
			wait(0.05)
			rootPart = humanoid.RootPart
		end

		if rootPart and promise:IsPending() then
			promise:Resolve(rootPart)
		end
	end)

	return promise
end

return lib