Class: Anschel::Output::Device

Inherits:
Base
  • Object
show all
Defined in:
lib/anschel/output/device.rb

Instance Method Summary collapse

Methods inherited from Base

#push, #stop

Constructor Details

#initialize(config, stats, log) ⇒ Device

Returns a new instance of Device.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/anschel/output/device.rb', line 9

def initialize config, stats, log
  path   = config.delete(:path) || '/dev/stdout'
  qsize  = config.delete(:queue_size) || 2000
  @queue = SizedQueue.new qsize

  @thread = Thread.new do
    File.open(path, 'w') do |f|
      loop do
        f.puts @queue.shift
        f.flush
        stats.inc 'output'
      end
    end
  end
end