Class: Conrad::EmitterQueue

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/conrad/emitter_queue.rb

Overview

Centralized event emission queue across threads

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEmitterQueue

Returns a new instance of EmitterQueue.



13
14
15
16
17
# File 'lib/conrad/emitter_queue.rb', line 13

def initialize
  @thread = nil
  @queue = Queue.new
  @logger ||= Logger.new(STDOUT)
end

Instance Attribute Details

#backgroundObject

Boolean that determines whether events will be emitted inline or in a

background thread


8
9
10
# File 'lib/conrad/emitter_queue.rb', line 8

def background
  @background
end

#loggerObject

Logger object used for sending log events



11
12
13
# File 'lib/conrad/emitter_queue.rb', line 11

def logger
  @logger
end

Instance Method Details

#enqueue { ... } ⇒ Object

Enqueues a block

Yields:

  • block to execute. Will either run inline or separately depending on whether the queue is backgrounded



30
31
32
33
34
35
36
# File 'lib/conrad/emitter_queue.rb', line 30

def enqueue
  @queue.push -> { yield }

  # if it's backgounded we can break out of here, as the background
  #   queue will pick it up. otherwise, we need to explicitly process it
  emit! unless @background
end