Skip to content

Commit 1b24e0b

Browse files
author
Petr Chalupa
committed
Merge pull request #431 from pitr-ch/futures
rescue Exception in Futures
2 parents 10ceb96 + 2f5af57 commit 1b24e0b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/concurrent/edge/future.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def post_on(executor, *args, &job)
132132
class Event < Synchronization::LockableObject
133133
safe_initialization!
134134
include Concern::Deprecation
135+
include Concern::Logging
135136

136137
# @!visibility private
137138
class State
@@ -885,6 +886,7 @@ def hide_completable
885886
# @!visibility private
886887
class AbstractPromise < Synchronization::Object
887888
safe_initialization!
889+
include Concern::Logging
888890

889891
def initialize(future)
890892
super()
@@ -925,7 +927,10 @@ def complete_with(new_state, raise_on_reassign = true)
925927
# @return [Future]
926928
def evaluate_to(*args, block)
927929
complete_with Future::Success.new(block.call(*args))
928-
rescue => error
930+
rescue StandardError => error
931+
complete_with Future::Failed.new(error)
932+
rescue Exception => error
933+
log(ERROR, 'Edge::Future', error)
929934
complete_with Future::Failed.new(error)
930935
end
931936
end

spec/concurrent/edge/future_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@
334334
expect(f.reason).to be_an_instance_of TypeError
335335
end
336336
end
337+
338+
it 'completes future when Exception raised' do
339+
f = Concurrent.future { raise Exception, 'fail' }
340+
f.wait 1
341+
expect(f).to be_completed
342+
expect(f).to be_failed
343+
expect{ f.value! }.to raise_error(Exception, 'fail')
344+
end
337345
end
338346

339347
describe 'interoperability' do

0 commit comments

Comments
 (0)