]> jaekl.net Git - quanlib.git/blob - book_loader.rb
Multi-thread the parsing of books to speed up loading.
[quanlib.git] / book_loader.rb
1
2 require_relative 'book'
3 require_relative 'store'
4
5 class BookLoader 
6   DONE_MARKER = '<END>'
7
8   def initialize(config_file, queue)
9     @config_file = config_file
10     @queue = queue
11   end
12
13   def run
14     @store = Store.new(@config_file)
15     @store.connect()
16
17     file = @queue.pop
18     until file == DONE_MARKER do
19       book = Book.new(@store)
20       book.load_from_file!(file)
21       @store.store_book(book)
22
23       file = @queue.pop
24     end
25
26     @store.disconnect()
27   end
28 end