Class: Debouncer
- Inherits:
-
Object
- Object
- Debouncer
- Defined in:
- lib/rox/core/utils/debouncer.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(delay_in_seconds, block) ⇒ Debouncer
constructor
A new instance of Debouncer.
Constructor Details
#initialize(delay_in_seconds, block) ⇒ Debouncer
Returns a new instance of Debouncer.
2 3 4 5 6 |
# 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 |
Instance Method Details
#call ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# 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 |