Class: BeerBot::Utils::InOut
- Inherits:
-
Object
- Object
- BeerBot::Utils::InOut
- Defined in:
- lib/beerbot/00.utils/InOut.rb
Overview
Represents a thread that waits on an in-queue, processes any things received and puts them on an out-queue.
Instance Attribute Summary collapse
-
#inq ⇒ Object
readonly
Returns the value of attribute inq.
-
#outq ⇒ Object
readonly
Returns the value of attribute outq.
-
#run ⇒ Object
readonly
Returns the value of attribute run.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(inq: nil, outq: nil, &block) ⇒ InOut
constructor
A new instance of InOut.
- #start! ⇒ Object
Constructor Details
#initialize(inq: nil, outq: nil, &block) ⇒ InOut
Returns a new instance of InOut.
18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#inq ⇒ Object (readonly)
Returns the value of attribute inq.
16 17 18 |
# File 'lib/beerbot/00.utils/InOut.rb', line 16 def inq @inq end |
#outq ⇒ Object (readonly)
Returns the value of attribute outq.
16 17 18 |
# File 'lib/beerbot/00.utils/InOut.rb', line 16 def outq @outq end |
#run ⇒ Object (readonly)
Returns the value of attribute run.
16 17 18 |
# File 'lib/beerbot/00.utils/InOut.rb', line 16 def run @run end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
16 17 18 |
# File 'lib/beerbot/00.utils/InOut.rb', line 16 def thread @thread end |
Instance Method Details
#start! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |