From 735e4d24a9d3674a3059b20260b808056aec6446 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 19 Jun 2015 22:32:13 +0200 Subject: Add #perform_disconnection to have a place for both callbacks and logging And using an unlikely-to-clash name. --- lib/action_cable/channel/base.rb | 13 ++++++++----- lib/action_cable/connection/base.rb | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb index c18593bf6f..8580f9d75b 100644 --- a/lib/action_cable/channel/base.rb +++ b/lib/action_cable/channel/base.rb @@ -56,11 +56,9 @@ module ActionCable send(callback) end end - - def run_unsubscribe_callbacks - self.class.on_unsubscribe_callbacks.each do |callback| - send(callback) - end + def perform_disconnection + run_unsubscribe_callbacks + logger.info "#{self.class.name} disconnected" end protected @@ -89,6 +87,11 @@ module ActionCable end end + private + def run_unsubscribe_callbacks + self.class.on_unsubscribe_callbacks.each { |callback| send(callback) } + end + def start_periodic_timers self.class.periodic_timers.each do |callback, options| @_active_periodic_timers << EventMachine::PeriodicTimer.new(options[:every]) do diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb index e5ed07b5cc..2ae5c5554c 100644 --- a/lib/action_cable/connection/base.rb +++ b/lib/action_cable/connection/base.rb @@ -81,7 +81,7 @@ module ActionCable def cleanup_subscriptions @subscriptions.each do |id, channel| - channel.run_unsubscribe_callbacks + channel.perform_disconnection end end @@ -161,7 +161,7 @@ module ActionCable def unsubscribe_channel(data) logger.info "Unsubscribing from channel: #{data['identifier']}" - @subscriptions[data['identifier']].run_unsubscribe_callbacks + @subscriptions[data['identifier']].perform_disconnection @subscriptions.delete(data['identifier']) end -- cgit v1.2.3