Sha256: 1ffad7dce583cfc615103b51d88567485043f4148f745327fcbf28a6f0ed6dab

Contents?: true

Size: 453 Bytes

Versions: 20

Compression:

Stored size: 453 Bytes

Contents

class Turbo::Debouncer
  attr_reader :delay, :scheduled_task

  DEFAULT_DELAY = 0.5

  def initialize(delay: DEFAULT_DELAY)
    @delay = delay
    @scheduled_task = nil
  end

  def debounce(&block)
    scheduled_task&.cancel unless scheduled_task&.complete?
    @scheduled_task = Concurrent::ScheduledTask.execute(delay, &block)
  end

  def wait
    scheduled_task&.wait(wait_timeout)
  end

  private
    def wait_timeout
      delay + 1
    end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
turbo-rails-2.0.11 app/models/turbo/debouncer.rb
turbo-rails-2.0.10 app/models/turbo/debouncer.rb
turbo-rails-2.0.9 app/models/turbo/debouncer.rb
turbo-rails-2.0.8 app/models/turbo/debouncer.rb
turbo-rails-2.0.7 app/models/turbo/debouncer.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/turbo-rails-2.0.5/app/models/turbo/debouncer.rb
turbo-rails-2.0.6 app/models/turbo/debouncer.rb
turbo-rails-2.0.5 app/models/turbo/debouncer.rb
turbo-rails-2.0.4 app/models/turbo/debouncer.rb
turbo-rails-2.0.3 app/models/turbo/debouncer.rb
turbo-rails-2.0.2 app/models/turbo/debouncer.rb
turbo-rails-2.0.1 app/models/turbo/debouncer.rb
turbo-rails-2.0.0 app/models/turbo/debouncer.rb
turbo-rails-2.0.0.pre.rc.3 app/models/turbo/debouncer.rb
turbo-rails-2.0.0.pre.rc.2 app/models/turbo/debouncer.rb
turbo-rails-2.0.0.pre.rc.1 app/models/turbo/debouncer.rb
turbo-rails-2.0.0.pre.beta.4 app/models/turbo/debouncer.rb
turbo-rails-2.0.0.pre.beta.3 app/models/turbo/debouncer.rb
turbo-rails-2.0.0.pre.beta.2 app/models/turbo/debouncer.rb
turbo-rails-2.0.0.pre.beta.1 app/models/turbo/debouncer.rb