diff options
Diffstat (limited to 'lib/action_cable/channel/callbacks.rb')
-rw-r--r-- | lib/action_cable/channel/callbacks.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/action_cable/channel/callbacks.rb b/lib/action_cable/channel/callbacks.rb new file mode 100644 index 0000000000..cf0246a386 --- /dev/null +++ b/lib/action_cable/channel/callbacks.rb @@ -0,0 +1,32 @@ +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 periodic_timer(method, every:) + self.periodic_timers += [ [ method, every: every ] ] + end + end + + end + + end +end
\ No newline at end of file |