Class: CottonTail::Queue::Reader
- Inherits:
-
Object
- Object
- CottonTail::Queue::Reader
- Defined in:
- lib/cotton_tail/queue/reader.rb
Overview
Queue Reader
Class Method Summary collapse
Instance Method Summary collapse
- #fiber ⇒ Object
-
#initialize(queue, app:) ⇒ Reader
constructor
A new instance of Reader.
- #start ⇒ Object
Constructor Details
#initialize(queue, app:) ⇒ Reader
Returns a new instance of Reader.
13 14 15 16 |
# File 'lib/cotton_tail/queue/reader.rb', line 13 def initialize(queue, app:) @queue = queue @app = app end |
Class Method Details
.spawn(queue, **kwargs) ⇒ Object
9 10 11 |
# File 'lib/cotton_tail/queue/reader.rb', line 9 def self.spawn(queue, **kwargs) Thread.new { new(queue, **kwargs).start } end |
Instance Method Details
#fiber ⇒ Object
18 19 20 21 22 |
# File 'lib/cotton_tail/queue/reader.rb', line 18 def fiber @fiber ||= Fiber.new do Fiber.yield @queue.pop until @queue.empty? && @queue.closed? end end |
#start ⇒ Object
24 25 26 |
# File 'lib/cotton_tail/queue/reader.rb', line 24 def start call_next while fiber.alive? end |