Class: ActionCable::SubscriptionAdapter::SolidCable::Listener

Inherits:
ActionCable::SubscriptionAdapter::SubscriberMap
  • Object
show all
Defined in:
lib/action_cable/subscription_adapter/solid_cable.rb

Instance Method Summary collapse

Constructor Details

#initialize(event_loop) ⇒ Listener

Returns a new instance of Listener.



41
42
43
44
45
46
47
48
49
50
# File 'lib/action_cable/subscription_adapter/solid_cable.rb', line 41

def initialize(event_loop)
  super()

  @event_loop = event_loop

  @thread = Thread.new do
    Thread.current.abort_on_exception = true
    listen
  end
end

Instance Method Details

#add_channel(channel, on_success) ⇒ Object



65
66
67
68
# File 'lib/action_cable/subscription_adapter/solid_cable.rb', line 65

def add_channel(channel, on_success)
  channels.add(channel)
  event_loop.post(&on_success) if on_success
end

#invoke_callbackObject



74
75
76
# File 'lib/action_cable/subscription_adapter/solid_cable.rb', line 74

def invoke_callback(*)
  event_loop.post { super }
end

#listenObject



52
53
54
55
56
57
58
# File 'lib/action_cable/subscription_adapter/solid_cable.rb', line 52

def listen
  while running?
    with_polling_volume { broadcast_messages }

    sleep ::SolidCable.polling_interval
  end
end

#remove_channel(channel) ⇒ Object



70
71
72
# File 'lib/action_cable/subscription_adapter/solid_cable.rb', line 70

def remove_channel(channel)
  channels.delete(channel)
end

#shutdownObject



60
61
62
63
# File 'lib/action_cable/subscription_adapter/solid_cable.rb', line 60

def shutdown
  self.running = false
  Thread.pass while thread.alive?
end