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



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

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

#invoke_callbackObject



80
81
82
# File 'lib/action_cable/subscription_adapter/solid_cable.rb', line 80

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

#listenObject



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

def listen
  loop do
    break unless running?

    with_polling_volume { broadcast_messages }

    interruptible_sleep ::SolidCable.polling_interval
  end
end

#remove_channel(channel) ⇒ Object



76
77
78
# File 'lib/action_cable/subscription_adapter/solid_cable.rb', line 76

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

#shutdownObject



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

def shutdown
  self.running = false
  wake_up

  ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
    thread&.join
  end
end