Class: Conrad::EmitterQueue
- Inherits:
-
Object
- Object
- Conrad::EmitterQueue
- Includes:
- Singleton
- Defined in:
- lib/conrad/emitter_queue.rb
Overview
Centralized event emission queue across threads
Instance Attribute Summary collapse
-
#background ⇒ Object
Boolean that determines whether events will be emitted inline or in a background thread.
-
#logger ⇒ Object
Logger object used for sending log events.
Instance Method Summary collapse
-
#enqueue { ... } ⇒ Object
Enqueues a block.
-
#initialize ⇒ EmitterQueue
constructor
A new instance of EmitterQueue.
Constructor Details
#initialize ⇒ EmitterQueue
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
#background ⇒ Object
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 |
#logger ⇒ Object
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
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 |