Skip to content

Commit

Permalink
Ensure thread-pool shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Sep 7, 2024
1 parent 69a04bd commit b68ee41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Library/Homebrew/cmd/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ def run
# FIXME: Implement cancellation of running downloads.
end

download_queue.cancel

Check warning on line 304 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L304

Added line #L304 was not covered by tests

if previous_pending_line_count.positive?
$stdout.print Tty.move_cursor_down(previous_pending_line_count - 1)
$stdout.flush

Check warning on line 308 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L308

Added line #L308 was not covered by tests
Expand All @@ -314,7 +316,7 @@ def run
$stdout.flush

Check warning on line 316 in Library/Homebrew/cmd/fetch.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/fetch.rb#L315-L316

Added lines #L315 - L316 were not covered by tests
end
end

ensure
download_queue.shutdown
end

Expand Down
9 changes: 9 additions & 0 deletions Library/Homebrew/download_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ def enqueue(downloadable, force: false)
# rubocop:enable Lint/ShadowingOuterLocalVariable
end

sig { void }
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

Check warning on line 36 in Library/Homebrew/download_queue.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/download_queue.rb#L36

Added line #L36 was not covered by tests
end

sig { void }
def shutdown
pool.shutdown
pool.wait_for_termination
end
end
end

0 comments on commit b68ee41

Please sign in to comment.