--[[**
	This function allows the developer to schedule the removal of the object without yielding any code. It is the suggested alternative to Debris:AddItem, as this doesn't use the legacy scheduler and also supports tables with a Destroy / destroy method.

	@param [t:union<t:Instance, t:table, t:RBXScriptConnection, t:userdata>] Object The object to be added to destroy scheduler.
	@param [t:optional<t:numberMin<0>>] Lifetime The number of seconds before the object should be destroyed. Defaults to 10.
	@returns [void]
**--]]

function Scheduler.AddItem(Object, Lifetime)
	assert(AddItemTuple(Object, Lifetime))
	local ExecuteTime = tick() + (Lifetime or 10)
	local Connection

	Connection = Heartbeat:Connect(function()
		if tick() >= ExecuteTime then
			Connection:Disconnect()
			if Object then
				if Object.Destroy then
					pcall(Object.Destroy, Object)
				elseif Object.destroy then
					pcall(Object.destroy, Object)
				elseif Object.Disconnect then
					pcall(Object.Disconnect, Object)
				elseif Object.disconnect then
					pcall(Object.disconnect, Object)
				end
			end
		end
	end)

	return Connection
end

return Scheduler
