class BeerBot::Utils::InOut

Represents a thread that waits on an in-queue, processes any things received and puts them on an out-queue.

Attributes

inq[R]
outq[R]
run[R]
thread[R]

Private Class Methods

new(inq:nil,outq:nil,&block) click to toggle source
# File lib/beerbot/00.utils/InOut.rb, line 18
def initialize inq:nil,outq:nil,&block
  @inq = inq
  @outq = outq
  @run = block
  raise "No block given" unless block_given?
end

Private Instance Methods

start!() click to toggle source
# File lib/beerbot/00.utils/InOut.rb, line 25
def start!
  @thread = Thread.new {
    loop {
      begin
        thing = @inq.deq
        response = @run.call(thing)
        if response then
          @outq.enq(response)
        else
          # TODO
        end
      rescue => e
        puts e
        puts e.backtrace
      end
    }
  }
end