Lua Logo

Lua: Debounce utility function

function debounce(func, delay) ⏎
	local timer
	return function(...)
		local context = self
		local args = {...}
		if timer then
			timer:stop()
		end
		timer = os.startTimer(delay)
		local function onTimer()
			func(table.unpack(args))
		end
		timer:connect("timeout", onTimer)
	end
end
Accuracy
100 %
0 Mistakes
CPM
0
Average: 0 CPM
Time
0.000 s
Personal best: -.--- s