Class: Kafka::AsyncProducer::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/async_producer.rb

Instance Method Summary collapse

Constructor Details

#initialize(interval:, queue:) ⇒ Timer

Returns a new instance of Timer.



156
157
158
159
# File 'lib/kafka/async_producer.rb', line 156

def initialize(interval:, queue:)
  @queue = queue
  @interval = interval
end

Instance Method Details

#runObject



161
162
163
164
165
166
167
168
169
# File 'lib/kafka/async_producer.rb', line 161

def run
  # Permanently sleep if the timer interval is zero.
  Thread.stop if @interval.zero?

  loop do
    sleep(@interval)
    @queue << [:deliver_messages, nil]
  end
end