Class: GemChangelogDiff::ConcurrentFetcher

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

Overview

Thread pool for fetching multiple gems in parallel.

Instance Method Summary collapse

Constructor Details

#initialize(concurrency: 4) ⇒ ConcurrentFetcher

Returns a new instance of ConcurrentFetcher.



8
9
10
# File 'lib/gem_changelog_diff/concurrent_fetcher.rb', line 8

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

Instance Method Details

#fetch_all(items) {|item| ... } ⇒ Array

Processes items concurrently, returning results in order.

Parameters:

  • items (Array)

    items to process

Yields:

  • (item)

    block called for each item

Returns:

  • (Array)

    results in the same order as items

Raises:



17
18
19
20
21
22
23
24
# File 'lib/gem_changelog_diff/concurrent_fetcher.rb', line 17

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

  total_timeout = GemChangelogDiff.configuration.total_timeout
  Timeout.timeout(total_timeout, NetworkError, "Total timeout of #{total_timeout}s exceeded") do
    run_workers(items, &)
  end
end