Class: RailsMetrics::AsyncConsumer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_metrics/async_consumer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue = Queue.new, &block) ⇒ AsyncConsumer

Returns a new instance of AsyncConsumer.


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_metrics/async_consumer.rb', line 16

def initialize(queue=Queue.new, &block)
  @off   = true
  @block = block
  @queue = queue
  @mutex = Mutex.new

  @thread = Thread.new do
    set_void_instrumenter
    consume
  end
end

Instance Attribute Details

#threadObject (readonly)

Returns the value of attribute thread


14
15
16
# File 'lib/rails_metrics/async_consumer.rb', line 14

def thread
  @thread
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'lib/rails_metrics/async_consumer.rb', line 33

def finished?
  @off
end

#push(*args) ⇒ Object


28
29
30
31
# File 'lib/rails_metrics/async_consumer.rb', line 28

def push(*args)
  @mutex.synchronize { @off = false }
  @queue.push(*args)
end