Class: GemChangelogDiff::ConcurrentFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_changelog_diff/concurrent_fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(concurrency: 4) ⇒ ConcurrentFetcher

Returns a new instance of ConcurrentFetcher.



5
6
7
# File 'lib/gem_changelog_diff/concurrent_fetcher.rb', line 5

def initialize(concurrency: 4)
  @concurrency = concurrency
end

Instance Method Details

#fetch_all(items) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gem_changelog_diff/concurrent_fetcher.rb', line 9

def fetch_all(items, &)
  return items.map(&) if @concurrency <= 1

  results = Array.new(items.size)
  queue = Queue.new
  items.each_with_index { |item, i| queue << [item, i] }

  threads = spawn_workers(queue, results, &)
  threads.each(&:join)
  results
end