Class: CottonTail::Queue::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/cotton_tail/queue/reader.rb

Overview

Queue Reader

Class Method Summary collapse

Instance Method Summary collapse

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

#fiberObject



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

#startObject



24
25
26
# File 'lib/cotton_tail/queue/reader.rb', line 24

def start
  call_next while fiber.alive?
end