lib/redis/subscribe.rb in redis-3.2.2 vs lib/redis/subscribe.rb in redis-3.3.0

- old
+ new

@@ -10,30 +10,38 @@ def subscribe(*channels, &block) subscription("subscribe", "unsubscribe", channels, block) end + def subscribe_with_timeout(timeout, *channels, &block) + subscription("subscribe", "unsubscribe", channels, block, timeout) + end + def psubscribe(*channels, &block) subscription("psubscribe", "punsubscribe", channels, block) end + def psubscribe_with_timeout(timeout, *channels, &block) + subscription("psubscribe", "punsubscribe", channels, block, timeout) + end + def unsubscribe(*channels) call([:unsubscribe, *channels]) end def punsubscribe(*channels) call([:punsubscribe, *channels]) end protected - def subscription(start, stop, channels, block) + def subscription(start, stop, channels, block, timeout = 0) sub = Subscription.new(&block) unsubscribed = false begin - @client.call_loop([start, *channels]) do |line| + @client.call_loop([start, *channels], timeout) do |line| type, *rest = line sub.callbacks[type].call(*rest) unsubscribed = type == stop && rest.last == 0 break if unsubscribed end