Class: RCrawler::Async

Inherits:
Object
  • Object
show all
Defined in:
lib/rcrawler/async.rb

Instance Method Summary collapse

Constructor Details

#initializeAsync

Returns a new instance of Async.



7
8
9
10
# File 'lib/rcrawler/async.rb', line 7

def initialize
  @queue = ::Queue.new
  @config = ::RCrawler::Configuration.instance
end

Instance Method Details

#crawl(&block) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
# File 'lib/rcrawler/async.rb', line 12

def crawl(&block)
  raise ArgumentError, "crawl method is required block" unless block_given?
  @queue.push block
end

#executeObject



17
18
19
20
21
22
23
# File 'lib/rcrawler/async.rb', line 17

def execute
  threads = []
  @config.threads.times do
    threads << create_thread
  end
  threads.each {|thread| thread.join}
end