Skip to content

Commit dcff3c1

Browse files
authored
Merge pull request #569 from davishmcclurg/promise-exception
Reject promise on any exception
2 parents d2cf37b + 0e4e5b9 commit dcff3c1

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)