function Trove.AddPromise(l,P)if l._cleaning then error("\067\097\110\110\111\116 \099\097\108\108 \116\114\111\118\101\058\065\100\100\080\114\111\109\105\115\101\040\041 \119\104\105\108\101 \099\108\101\097\110\105\110\103",2)end AssertPromiseLike(P)if P:getStatus()=="\083\116\097\114\116\101\100"then P:finally(function()if l._cleaning then return end l:_findAndRemoveFromObjects(P,false)end)l:Add(P,"\099\097\110\099\101\108")end return P end
--[=[
	@param promise Promise
	@return Promise
	Gives the promise to the trove, which will cancel the promise if the trove is cleaned up or if the promise
	is removed. The exact promise is returned, thus allowing chaining.

	```lua
	trove:AddPromise(doSomethingThatReturnsAPromise())
		:andThen(function()
			print("Done")
		end)
	-- Will cancel the above promise (assuming it didn't resolve immediately)
	trove:Clean()

	local p = trove:AddPromise(doSomethingThatReturnsAPromise())
	-- Will also cancel the promise
	trove:Remove(p)
	```

	:::caution Promise v4 Only
	This is only compatible with the [roblox-lua-promise](https://eryn.io/roblox-lua-promise/) library, version 4.
	:::
]=]
function Trove:AddPromise(promise)
	if self._cleaning then
		error("Cannot call trove:AddPromise() while cleaning", 2)
	end
	AssertPromiseLike(promise)
	if promise:getStatus() == "Started" then
		promise:finally(function()
			if self._cleaning then
				return
			end
			self:_findAndRemoveFromObjects(promise, false)
		end)
		self:Add(promise, "cancel")
	end
	return promise
end
