Ruby Logo

Ruby: Throttle utility function

def throttle(wait) ⏎
	return proc do |&block|
		last_call = 0
		proc do |*args, &inner_block|
			current_time = Time.now.to_f
			if current_time - last_call >= wait
				last_call = current_time
				block.call(*args, &inner_block)
			end
		end
	end
end
Accuracy
100 %
0 Mistakes
CPM
0
Average: 0 CPM
Time
0.000 s
Personal best: 80.664 s