Skip to content

Commit

Permalink
Merge pull request #431 from pitr-ch/futures
Browse files Browse the repository at this point in the history
rescue Exception in Futures
  • Loading branch information
Petr Chalupa committed Sep 30, 2015
2 parents 10ceb96 + 2f5af57 commit 1b24e0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/concurrent/edge/future.rb
Expand Up @@ -132,6 +132,7 @@ def post_on(executor, *args, &job)
class Event < Synchronization::LockableObject
safe_initialization!
include Concern::Deprecation
include Concern::Logging

# @!visibility private
class State
Expand Down Expand Up @@ -885,6 +886,7 @@ def hide_completable
# @!visibility private
class AbstractPromise < Synchronization::Object
safe_initialization!
include Concern::Logging

def initialize(future)
super()
Expand Down Expand Up @@ -925,7 +927,10 @@ def complete_with(new_state, raise_on_reassign = true)
# @return [Future]
def evaluate_to(*args, block)
complete_with Future::Success.new(block.call(*args))
rescue => error
rescue StandardError => error
complete_with Future::Failed.new(error)
rescue Exception => error
log(ERROR, 'Edge::Future', error)
complete_with Future::Failed.new(error)
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/concurrent/edge/future_spec.rb
Expand Up @@ -334,6 +334,14 @@
expect(f.reason).to be_an_instance_of TypeError
end
end

it 'completes future when Exception raised' do
f = Concurrent.future { raise Exception, 'fail' }
f.wait 1
expect(f).to be_completed
expect(f).to be_failed
expect{ f.value! }.to raise_error(Exception, 'fail')
end
end

describe 'interoperability' do
Expand Down

0 comments on commit 1b24e0b

Please sign in to comment.