Class: RCrawler::Async
- Inherits:
-
Object
- Object
- RCrawler::Async
- Defined in:
- lib/rcrawler/async.rb
Instance Method Summary collapse
- #crawl(&block) ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ Async
constructor
A new instance of Async.
Constructor Details
#initialize ⇒ Async
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
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 |
#execute ⇒ Object
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 |