1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actioncable/lib/action_cable/subscription_adapter/inline.rb
Matthew Draper 16a6603956 Synchronize the lazy setters in Server
They're all at risk of races on the first requests.
2016-01-30 03:46:37 +10:30

35 lines
817 B
Ruby

module ActionCable
module SubscriptionAdapter
class Inline < Base # :nodoc:
def initialize(*)
super
@subscriber_map = nil
end
def broadcast(channel, payload)
subscriber_map.broadcast(channel, payload)
end
def subscribe(channel, callback, success_callback = nil)
subscriber_map.add_subscriber(channel, callback, success_callback)
end
def unsubscribe(channel, callback)
subscriber_map.remove_subscriber(channel, callback)
end
def shutdown
# nothing to do
end
private
def subscriber_map
@subscriber_map || @server.mutex.synchronize { @subscriber_map ||= new_subscriber_map }
end
def new_subscriber_map
SubscriberMap.new
end
end
end
end