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