brew/Library/Homebrew/download_queue.rb

32 lines
725 B
Ruby
Raw Normal View History

2024-07-14 11:42:22 -04:00
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
require "downloadable"
2024-07-15 10:25:25 -04:00
require "concurrent/promise"
require "concurrent/executors"
2024-07-14 11:42:22 -04:00
module Homebrew
class DownloadQueue
sig { returns(Concurrent::FixedThreadPool) }
attr_reader :pool
private :pool
sig { params(size: Integer).void }
def initialize(size = 1)
@pool = Concurrent::FixedThreadPool.new(size)
end
sig { params(downloadable: Downloadable).returns(Concurrent::Promise) }
def enqueue(downloadable)
Concurrent::Promise.execute(executor: pool) do
downloadable.fetch(quiet: pool.max_length > 1)
end
end
sig { void }
def shutdown
pool.shutdown
end
end
end