function FunctionUtils.throttle(a,z)assert(FunctionUtils.isCallable(a))assert(type(z)=="\110\117\109\098\101\114")assert(z>0)local d=false local m=nil return function(...)if not d then d=true m=a(...)delay(z,function()d=false end)end return m end end function FunctionUtils.isCallable(a)return type(a)=="\102\117\110\099\116\105\111\110"or type(a)=="\116\097\098\108\101"and(getmetatable(a)and(getmetatable(a)).__call~=nil)end return FunctionUtils

function FunctionUtils.throttle(fn, secondsCooldown)
	assert(FunctionUtils.isCallable(fn))
	assert(type(secondsCooldown) == "number")
	assert(secondsCooldown > 0)

	local cached = false
	local lastResult = nil

	return function(...)
		if not cached then
			cached = true
			lastResult = fn(...)
			delay(
				secondsCooldown,
				function()
					cached = false
				end
			)
		end
		return lastResult
	end
end

function FunctionUtils.isCallable(thing)
	return type(thing) == "function" or
		(type(thing) == "table" and getmetatable(thing) and getmetatable(thing).__call ~= nil)
end

return FunctionUtils
