Module: Philiprehberger::Debounce
- Defined in:
- lib/philiprehberger/debounce.rb,
lib/philiprehberger/debounce/mixin.rb,
lib/philiprehberger/debounce/version.rb,
lib/philiprehberger/debounce/debouncer.rb,
lib/philiprehberger/debounce/throttler.rb
Overview
Debounce and throttle decorators for Ruby method calls
Defined Under Namespace
Modules: Mixin Classes: Debouncer, Error, Throttler
Constant Summary collapse
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.debounce(wait:, leading: false, trailing: true) {|*args| ... } ⇒ Debouncer
Create a new debouncer that delays execution until the wait period elapses without new calls.
-
.throttle(interval:, leading: true, trailing: false) {|*args| ... } ⇒ Throttler
Create a new throttler that limits execution to at most once per interval.
Class Method Details
.debounce(wait:, leading: false, trailing: true) {|*args| ... } ⇒ Debouncer
Create a new debouncer that delays execution until the wait period elapses without new calls.
21 22 23 |
# File 'lib/philiprehberger/debounce.rb', line 21 def self.debounce(wait:, leading: false, trailing: true, &block) Debouncer.new(wait: wait, leading: leading, trailing: trailing, &block) end |
.throttle(interval:, leading: true, trailing: false) {|*args| ... } ⇒ Throttler
Create a new throttler that limits execution to at most once per interval.
32 33 34 |
# File 'lib/philiprehberger/debounce.rb', line 32 def self.throttle(interval:, leading: true, trailing: false, &block) Throttler.new(interval: interval, leading: leading, trailing: trailing, &block) end |