Skip to content

Commit

Permalink
If a task returns an exception value, do not raise it in #wait. (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
Math2 authored Aug 14, 2023
1 parent 7773705 commit 72ca9ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/async/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def wait
@finished.wait
end

if @result.is_a?(Exception)
if @status == :failed
raise @result
else
return @result
Expand Down
7 changes: 7 additions & 0 deletions test/async/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,13 @@ def sleep_forever
expect(error_task).to be(:finished?)
expect(innocent_task).to be(:finished?)
end

it "will not raise exception values returned by the task" do
error = StandardError.new
task = reactor.async { error }
expect(task.wait).to be == error
expect(task.result).to be == error
end
end

with '#result' do
Expand Down

0 comments on commit 72ca9ca

Please sign in to comment.