123456789_123456789_123456789_123456789_123456789_

Module: ActionCable::Channel::PeriodicTimers

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: actioncable/lib/action_cable/channel/periodic_timers.rb

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

Instance Method Summary

DSL Calls

included

[ GitHub ]


10
11
12
13
14
15
# File 'actioncable/lib/action_cable/channel/periodic_timers.rb', line 10

included do
  class_attribute :periodic_timers, instance_reader: false, default: []

  after_subscribe   :start_periodic_timers
  after_unsubscribe :stop_periodic_timers
end

Instance Method Details

#active_periodic_timers (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/channel/periodic_timers.rb', line 56

def active_periodic_timers
  @active_periodic_timers ||= []
end

#start_periodic_timer(callback, every:) (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/channel/periodic_timers.rb', line 66

def start_periodic_timer(callback, every:)
  connection.server.event_loop.timer every do
    connection.worker_pool.async_exec self, connection: connection, &callback
  end
end

#start_periodic_timers (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/channel/periodic_timers.rb', line 60

def start_periodic_timers
  self.class.periodic_timers.each do |callback, options|
    active_periodic_timers << start_periodic_timer(callback, every: options.fetch(:every))
  end
end

#stop_periodic_timers (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/channel/periodic_timers.rb', line 72

def stop_periodic_timers
  active_periodic_timers.each { |timer| timer.shutdown }
  active_periodic_timers.clear
end