Class: Termplot::Consumers::BaseConsumer::RendererThread

Inherits:
Object
  • Object
show all
Defined in:
lib/termplot/consumers/base_consumer.rb

Instance Method Summary collapse

Constructor Details

#initialize(renderer:, broker_pool:, &block) ⇒ RendererThread

Returns a new instance of RendererThread.



56
57
58
59
60
61
# File 'lib/termplot/consumers/base_consumer.rb', line 56

def initialize(renderer:, broker_pool:, &block)
  @renderer = renderer
  @broker_pool = broker_pool
  @block = block
  @thread = nil
end

Instance Method Details

#continueObject



83
84
85
# File 'lib/termplot/consumers/base_consumer.rb', line 83

def continue
  thread.run
end

#joinObject



91
92
93
# File 'lib/termplot/consumers/base_consumer.rb', line 91

def join
  thread.join unless thread.stop?
end

#pauseObject



87
88
89
# File 'lib/termplot/consumers/base_consumer.rb', line 87

def pause
  Thread.stop
end

#startObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/termplot/consumers/base_consumer.rb', line 63

def start
  @thread = Thread.new do
    # Pause and wait to be woken for rendering
    pause
    while !broker_pool.closed?
      num_samples = broker_pool.pending_message_count

      if num_samples.zero?
        pause
      else
        broker_pool.flush_messages

        if num_samples > 0
          renderer.render
        end
      end
    end
  end
end