Skip to content

Commit 8596155

Browse files
committed
evaluate_to should not rescue Exceptions
1 parent e7e9c49 commit 8596155

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/concurrent/promises.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ def evaluate_to(*args, &block)
12841284
# @return [self]
12851285
# @raise [Exception] also raise reason on rejection.
12861286
def evaluate_to!(*args, &block)
1287-
promise.evaluate_to!(*args, block)
1287+
promise.evaluate_to(*args, block).wait!
12881288
end
12891289

12901290
# Creates new future wrapping receiver, effectively hiding the resolve method and similar.
@@ -1343,8 +1343,8 @@ def resolve_with(new_state, raise_on_reassign = true)
13431343
def evaluate_to(*args, block)
13441344
resolve_with Fulfilled.new(block.call(*args))
13451345
rescue Exception => error
1346-
# TODO (pitr-ch 30-Jul-2016): figure out what should be rescued, there is an issue about it
13471346
resolve_with Rejected.new(error)
1347+
raise error unless error.is_a?(StandardError)
13481348
end
13491349
end
13501350

@@ -1368,10 +1368,6 @@ def reject(reason, raise_on_reassign)
13681368
end
13691369

13701370
public :evaluate_to
1371-
1372-
def evaluate_to!(*args, block)
1373-
evaluate_to(*args, block).wait!
1374-
end
13751371
end
13761372

13771373
# @abstract

spec/concurrent/edge/promises_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,17 @@ def behaves_as_delay(delay, value)
448448
end
449449

450450
it 'resolves future when Exception raised' do
451-
f = future { raise Exception, 'reject' }
452-
f.wait 1
453-
expect(f).to be_resolved
454-
expect(f).to be_rejected
455-
expect { f.value! }.to raise_error(Exception, 'reject')
451+
message = 'reject by an Exception'
452+
future = future { raise Exception, message }
453+
expect(future.wait(0.1)).to eq true
454+
future.wait
455+
expect(future).to be_resolved
456+
expect(future).to be_rejected
457+
458+
expect(future.reason).to be_instance_of Exception
459+
expect(future.result).to be_instance_of Array
460+
expect(future.value).to be_nil
461+
expect { future.value! }.to raise_error(Exception, message)
456462
end
457463

458464
it 'runs' do

0 commit comments

Comments
 (0)