local function a(a,L)assert(type(a)=="\110\117\109\098\101\114")assert(type(L)=="\102\117\110\099\116\105\111\110")local I=1 return function(...)I=I+1 local R=I local X={...}delay(a,function()if I==R then L(unpack(X))end end)end end return a
--- debounce a existing function by timeout
-- @module debounce

--- Provides a debounce function call on an operation
-- @tparam number timeout
-- @tparam function func
-- @treturn function
local function debounce(timeout, func)
	assert(type(timeout) == "number")
	assert(type(func) == "function")

	local key = 1
	return function(...)
		key = key + 1
		local localKey = key
		local args = {...}

		delay(timeout, function()
			if key == localKey then
				func(unpack(args))
			end
		end)
	end
end

return debounce