aboutsummaryrefslogblamecommitdiffstats
path: root/lib/action_cable/channel/callbacks.rb
blob: 22c6f2d5631a1dd56eb40c805adf486c4a962d72 (plain) (tree)






















                                                                                                                       

                                                                






           
module ActionCable
  module Channel

    module Callbacks
      extend ActiveSupport::Concern

      included do
        class_attribute :on_subscribe_callbacks, :on_unsubscribe_callbacks, :periodic_timers, :instance_reader => false

        self.on_subscribe_callbacks = []
        self.on_unsubscribe_callbacks = []
        self.periodic_timers = []
      end

      module ClassMethods
        def on_subscribe(*methods)
          self.on_subscribe_callbacks += methods
        end

        def on_unsubscribe(*methods)
          self.on_unsubscribe_callbacks += methods
        end

        def periodically(callback, every:)
          self.periodic_timers += [ [ callback, every: every ] ]
        end
      end

    end

  end
end