Class: Flydata::SourceMysql::Parser::AsyncIO

Inherits:
Object
  • Object
show all
Defined in:
lib/flydata/source_mysql/parser/dump_parser.rb

Overview

Read and buffer data in a separate thread

Constant Summary collapse

MAX_ITEMS =
200

Instance Method Summary collapse

Constructor Details

#initialize(io, options = {}) ⇒ AsyncIO

Returns a new instance of AsyncIO.


619
620
621
622
623
624
625
626
627
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 619

def initialize(io, options = {})
  max_items = options[:max_items] ? options[:max_items] : MAX_ITEMS
  @io = io
  @queue = SizedQueue.new(max_items)
  _readline
  @last = @queue.shift
  @stop = false
  @thread = Thread.new(&method(:run))
end

Instance Method Details

#closeObject


647
648
649
650
651
652
653
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 647

def close
  @stop = true
  # remove an item if the queue is full.  Otherwise, the thread will not
  # wake up.
  @queue.shift if @queue.size == @queue.max
  @thread.join
end

#eof?Boolean

Returns:

  • (Boolean)

643
644
645
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 643

def eof?
  @last[:eof]
end

#posObject


639
640
641
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 639

def pos
  @last[:pos]
end

#readlineObject


629
630
631
632
633
634
635
636
637
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 629

def readline
  if @last[:eof]
    raise EOFError.new("end of file reached")
  else
    result = @last[:line]
    @last = @queue.shift
    result
  end
end