Skip to content

Commit a947ad6

Browse files
authored
Merge pull request #20329 from Homebrew/download_concurrency_auto
env_config: add `auto` option for `download_concurrency`
2 parents d90a421 + d15a0cd commit a947ad6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Library/Homebrew/env_config.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,16 @@ def devcmdrun?
634634
sig { returns(Integer) }
635635
def download_concurrency
636636
# TODO: document this variable when ready to publicly announce it.
637-
concurrency = ENV.fetch("HOMEBREW_DOWNLOAD_CONCURRENCY", 1).to_i
638-
concurrency = 1 if concurrency <= 1
639-
concurrency
637+
concurrency = ENV.fetch("HOMEBREW_DOWNLOAD_CONCURRENCY", 1)
638+
concurrency = if concurrency == "auto"
639+
require "os"
640+
require "hardware"
641+
Hardware::CPU.cores * 2
642+
else
643+
concurrency.to_i
644+
end
645+
646+
[concurrency, 1].max
640647
end
641648
end
642649
end

Library/Homebrew/env_config.rbi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module Homebrew
5+
module EnvConfig
6+
include Kernel
7+
end
8+
end

0 commit comments

Comments
 (0)