Class: Homebrew::DownloadQueue Private

Inherits:
Object
  • Object
show all
Defined in:
download_queue.rb

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Instance Method Summary collapse

Constructor Details

#initialize(size = 1) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • size (Integer) (defaults to: 1)


15
16
17
# File 'download_queue.rb', line 15

def initialize(size = 1)
  @pool = Concurrent::FixedThreadPool.new(size)
end

Instance Method Details

#cancelvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



32
33
34
35
36
37
# File 'download_queue.rb', line 32

def cancel
  # FIXME: Implement graceful cancellaction of running downloads based on
  #        https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Cancellation.html
  #        instead of killing the whole thread pool.
  pool.kill
end

#enqueue(downloadable, force: false) ⇒ Concurrent::Promises::Future

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • downloadable (Downloadable)
  • force (Boolean) (defaults to: false)

Returns:

  • (Concurrent::Promises::Future)


20
21
22
23
24
25
26
27
28
29
# File 'download_queue.rb', line 20

def enqueue(downloadable, force: false)
  quiet = pool.max_length > 1
  # Passing in arguments from outside into the future is a common  `concurrent-ruby` pattern.
  # rubocop:disable Lint/ShadowingOuterLocalVariable
  Concurrent::Promises.future_on(pool, downloadable, force, quiet) do |downloadable, force, quiet|
    downloadable.clear_cache if force
    downloadable.fetch(quiet:)
  end
  # rubocop:enable Lint/ShadowingOuterLocalVariable
end

#shutdownvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



40
41
42
43
# File 'download_queue.rb', line 40

def shutdown
  pool.shutdown
  pool.wait_for_termination
end