Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/concurrent/future.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def self.execute(opts = {}, &block)

# @!visibility private
def work # :nodoc:
success, val, reason = SafeTaskExecutor.new(@task).execute(*@args)
success, val, reason = SafeTaskExecutor.new(@task, rescue_exception: true).execute(*@args)
complete(success, val, reason)
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/concurrent/future_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ def trigger_observable(observable)
expect(future.value).to be_nil
end

it 'sets the value to nil when the handler raises Exception' do
future = Future.new(executor: executor){ raise Exception }.execute
expect(future.value).to be_nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also test that future.reason is set to the Exception instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for quick response!

I added a test case. Could you check it?

end

it 'sets the reason to the Exception instance when the handler raises Exception' do
future = Future.new(executor: executor){ raise Exception }.execute
expect(future.reason).to be_a(Exception)
end

it 'sets the state to :rejected when the handler raises an exception' do
future = Future.new(executor: executor){ raise StandardError }.execute
expect(future).to be_rejected
Expand Down