Skip to content

Commit

Permalink
Raise an exception if there are no threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 22, 2024
1 parent c13be08 commit 0c337b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/async/worker_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def close
#
# @parameter work [Proc] The work to be done.
def call(work)
if @threads.empty?
raise RuntimeError, "No threads available!"
end

handle = Handle.new(::Fiber.scheduler, ::Fiber.current, work)

begin
Expand Down
10 changes: 10 additions & 0 deletions test/async/worker_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@
end)
end.to raise_exception(ArgumentError, message: be == "Oops!")
end

with "#close" do
it "can be closed" do
worker_pool.close

expect do
worker_pool.call(proc{})
end.to raise_exception(RuntimeError)
end
end
end

0 comments on commit 0c337b8

Please sign in to comment.