Merge pull request #20573 from Homebrew/add-download-queue-helper

Create `DownloadQueue` helper to check concurrency and initialize
This commit is contained in:
Rylan Polster 2025-08-25 18:10:49 +00:00 committed by GitHub
commit 0e49c24705
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 4 deletions

View File

@ -27,7 +27,7 @@ module Cask
quarantine = true if quarantine.nil?
download_queue = Homebrew::DownloadQueue.new(pour: true) if Homebrew::EnvConfig.download_concurrency > 1
download_queue = Homebrew::DownloadQueue.new_if_concurrency_enabled(pour: true)
cask_installers = casks.map do |cask|
Installer.new(cask, binaries:, verbose:, force:, skip_cask_deps:, require_sha:, reinstall: true,
quarantine:, zap:, download_queue:)

View File

@ -81,7 +81,7 @@ module Homebrew
{}, T.nilable(T::Hash[T.nilable(Symbol), T::Array[T.any(Formula, Keg, Cask::Cask)]])
)
@to_formulae_and_casks[only] ||= begin
download_queue = Homebrew::DownloadQueue.new if Homebrew::EnvConfig.download_concurrency > 1
download_queue = Homebrew::DownloadQueue.new_if_concurrency_enabled
formulae_and_casks = downcased_unique_named.flat_map do |name|
load_and_fetch_full_formula_or_cask(name, only:, method:, warn:, download_queue:)
@ -160,7 +160,7 @@ module Homebrew
]),
)
@to_formulae_casks_unknowns[method] = begin
download_queue = Homebrew::DownloadQueue.new if Homebrew::EnvConfig.download_concurrency > 1
download_queue = Homebrew::DownloadQueue.new_if_concurrency_enabled
formulae_and_casks = downcased_unique_named.map do |name|
load_and_fetch_full_formula_or_cask(name, only:, method:, download_queue:)

View File

@ -244,7 +244,7 @@ module Homebrew
installed_casks, new_casks = casks.partition(&:installed?)
download_queue = Homebrew::DownloadQueue.new(pour: true) if Homebrew::EnvConfig.download_concurrency > 1
download_queue = Homebrew::DownloadQueue.new_if_concurrency_enabled(pour: true)
fetch_casks = Homebrew::EnvConfig.no_install_upgrade? ? new_casks : casks
if download_queue

View File

@ -12,6 +12,13 @@ module Homebrew
class DownloadQueue
include Utils::Output::Mixin
sig { params(retries: Integer, force: T::Boolean, pour: T::Boolean).returns(T.nilable(DownloadQueue)) }
def self.new_if_concurrency_enabled(retries: 1, force: false, pour: false)
return if Homebrew::EnvConfig.download_concurrency <= 1
new(retries:, force:, pour:)
end
sig { params(retries: Integer, force: T::Boolean, pour: T::Boolean).void }
def initialize(retries: 1, force: false, pour: false)
@concurrency = T.let(EnvConfig.download_concurrency, Integer)