Class: Flydata::SourceMysql::Parser::AsyncIO
- Inherits:
-
Object
- Object
- Flydata::SourceMysql::Parser::AsyncIO
- 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
- #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.
653 654 655 656 657 658 659 660 661 |
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 653 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
681 682 683 684 685 686 687 |
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 681 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
677 678 679 |
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 677 def eof? @last[:eof] end |
#pos ⇒ Object
673 674 675 |
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 673 def pos @last[:pos] end |
#readline ⇒ Object
663 664 665 666 667 668 669 670 671 |
# File 'lib/flydata/source_mysql/parser/dump_parser.rb', line 663 def readline if @last[:eof] raise EOFError.new("end of file reached") else result = @last[:line] @last = @queue.shift result end end |