class Debouncer
Public Class Methods
new(delay_in_seconds, block)
click to toggle source
# File lib/rox/core/utils/debouncer.rb, line 2 def initialize(delay_in_seconds, block) @delay_in_seconds = delay_in_seconds @block = block @delay_until = Time.now end
Public Instance Methods
call()
click to toggle source
# File lib/rox/core/utils/debouncer.rb, line 8 def call now = Time.now if now > @delay_until @delay_until = now + @delay_in_seconds Thread.new do sleep(@delay_in_seconds) @block.call end end end