Class: Flydata::Parser::Mysql::AsyncIO
- Inherits:
-
Object
- Object
- Flydata::Parser::Mysql::AsyncIO
- Defined in:
- lib/flydata/parser/mysql/dump_parser.rb
Overview
Read and buffer data in a separate thread
Constant Summary collapse
- MAX_ITEMS =
200
Instance Method Summary collapse
- #close ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(io, options = {}) ⇒ AsyncIO
constructor
A new instance of AsyncIO.
- #pos ⇒ Object
- #readline ⇒ Object
Constructor Details
#initialize(io, options = {}) ⇒ AsyncIO
Returns a new instance of AsyncIO.
691 692 693 694 695 696 697 698 699 |
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 691 def initialize(io, = {}) max_items = [:max_items] ? [: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
#close ⇒ Object
719 720 721 722 723 724 725 |
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 719 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
715 716 717 |
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 715 def eof? @last[:eof] end |
#pos ⇒ Object
711 712 713 |
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 711 def pos @last[:pos] end |
#readline ⇒ Object
701 702 703 704 705 706 707 708 709 |
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 701 def readline if @last[:eof] raise EOFError.new("end of file reached") else result = @last[:line] @last = @queue.shift result end end |