Skip to content

Commit

Permalink
Make Future respond_to :class and :is_a? so that code given a potenti…
Browse files Browse the repository at this point in the history
…ally futuristic value from Redis can figure out if it is a Future or not.
  • Loading branch information
airhorns committed Mar 28, 2013
1 parent c68673b commit f7bfcbd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/redis/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,13 @@ def value
::Kernel.raise(@object) if @object.kind_of?(::RuntimeError)
@object
end

def is_a?(other)
self.class.ancestors.include?(other)
end

def class
Future
end
end
end
12 changes: 12 additions & 0 deletions test/pipelining_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ def test_futures_raise_when_trying_to_access_their_values_too_early
end
end

def test_futures_can_be_identified
r.pipelined do
@result = r.sadd("foo", 1)
end

assert_equal true, @result.is_a?(Redis::Future)
if defined?(::BasicObject)
assert_equal true, @result.is_a?(::BasicObject)
end
assert_equal Redis::Future, @result.class
end

def test_returning_the_result_of_an_empty_pipeline
result = r.pipelined do
end
Expand Down

0 comments on commit f7bfcbd

Please sign in to comment.