Skip to content

Commit 0e4e5b9

Browse files
committed
Reject promise on any exception
Currently, promises will hang if an exception is raised that does not extend from StandardError. ``` Concurrent::Promise.execute { raise Exception }.value ... ``` This behavior is unexpected and seems likely to be wrong for most use cases. Futures already use `safe_execute` which includes the `rescue_exception` option.
1 parent d2cf37b commit 0e4e5b9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/concurrent/promise.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def complete(success, value, reason)
525525
# @!visibility private
526526
def realize(task)
527527
@executor.post do
528-
success, value, reason = SafeTaskExecutor.new(task).execute(*@args)
528+
success, value, reason = SafeTaskExecutor.new(task, rescue_exception: true).execute(*@args)
529529
complete(success, value, reason)
530530
end
531531
end

spec/concurrent/promise_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ def get_ivar_from_args(opts)
620620
expect(p.reason).to be_a ArgumentError
621621
end
622622

623+
it 'rejects on Exception' do
624+
p = Promise.new(executor: :immediate){ raise Exception }.execute
625+
expect(p).to be_rejected
626+
end
627+
623628
end
624629

625630
context 'aliases' do

0 commit comments

Comments
 (0)