lib/redis/subscribe.rb in redis-4.1.4 vs lib/redis/subscribe.rb in redis-4.2.0
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
class Redis
class SubscribedClient
def initialize(client)
@client = client
end
@@ -31,36 +32,33 @@
def punsubscribe(*channels)
call([:punsubscribe, *channels])
end
- protected
+ protected
def subscription(start, stop, channels, block, timeout = 0)
sub = Subscription.new(&block)
unsubscribed = false
- begin
- @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
- ensure
- # No need to unsubscribe here. The real client closes the connection
- # whenever an exception is raised (see #ensure_connected).
+ @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
+ # No need to unsubscribe here. The real client closes the connection
+ # whenever an exception is raised (see #ensure_connected).
end
end
class Subscription
attr :callbacks
def initialize
@callbacks = Hash.new do |hash, key|
- hash[key] = lambda { |*_| }
+ hash[key] = ->(*_) {}
end
yield(self)
end