Class: Chamomile::InputReader

Inherits:
Object
  • Object
show all
Defined in:
lib/chamomile/input_reader.rb

Overview

Background thread that reads stdin and feeds bytes through EscapeParser.

Instance Method Summary collapse

Constructor Details

#initialize(queue, input: $stdin) ⇒ InputReader

Returns a new instance of InputReader.



8
9
10
11
12
13
14
# File 'lib/chamomile/input_reader.rb', line 8

def initialize(queue, input: $stdin)
  @queue   = queue
  @input   = input
  @thread  = nil
  @running = false
  @parser  = EscapeParser.new
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/chamomile/input_reader.rb', line 33

def running?
  @running
end

#startObject



16
17
18
19
20
21
22
23
# File 'lib/chamomile/input_reader.rb', line 16

def start
  return @thread if @running

  @running = true
  @thread = Thread.new { read_loop }
  @thread.abort_on_exception = false
  @thread
end

#stopObject



25
26
27
28
29
30
31
# File 'lib/chamomile/input_reader.rb', line 25

def stop
  @running = false
  return unless @thread

  @thread.join(1)
  @thread = nil
end