Skip to content

Commit

Permalink
Fixed failing Agent and Promise tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdantonio committed Oct 11, 2013
1 parent 2abcd6d commit d633428
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/concurrent/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def value(timeout = 0)
alias_method :deref, :value

def rescue(clazz = nil, &block)
if block_given?
unless block.nil?
@mutex.synchronize do
@rescuers << Rescuer.new(clazz, block)
end
Expand All @@ -56,15 +56,15 @@ def rescue(clazz = nil, &block)
alias_method :on_error, :rescue

def validate(&block)
@validator = block if block_given?
@validator = block unless block.nil?
return self
end
alias_method :validates, :validate
alias_method :validate_with, :validate
alias_method :validates_with, :validate

def post(&block)
Agent.thread_pool.post{ work(&block) } if block_given?
Agent.thread_pool.post{ work(&block) } unless block.nil?
end

def <<(block)
Expand Down
4 changes: 2 additions & 2 deletions lib/concurrent/promise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def rescued?
# @return [Promise] the new promise
def then(&block)
child = @lock.synchronize do
block = Proc.new{|result| result } unless block_given?
block = Proc.new{|result| result } if block.nil?
@children << Promise.new(self, &block)
@children.last.on_reject(@reason) if rejected?
push(@children.last)
Expand All @@ -77,7 +77,7 @@ def then(&block)
#
# @return [self] so that additional chaining can occur
def rescue(clazz = nil, &block)
return self if fulfilled? || rescued? || ! block_given?
return self if fulfilled? || rescued? || block.nil?
@lock.synchronize do
rescuer = Rescuer.new(clazz, block)
if pending?
Expand Down
3 changes: 2 additions & 1 deletion spec/concurrent/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ module Concurrent

it 'ignores rescuers without a block' do
@expected = nil
Promise.new{ raise StandardError }.
subject.
rescue(StandardError).
rescue(StandardError){|ex| @expected = ex }
subject.post{ raise StandardError }
sleep(0.1)
@expected.should be_a(StandardError)
end
Expand Down

0 comments on commit d633428

Please sign in to comment.