123456789_123456789_123456789_123456789_123456789_

Class: ActionCable::Connection::MessageBuffer

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actioncable/lib/action_cable/connection/message_buffer.rb

Overview

Allows us to buffer messages received from the WebSocket before the ::ActionCable::Connection has been fully initialized, and is ready to receive them.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(connection) ⇒ MessageBuffer

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 10

def initialize(connection)
  @connection = connection
  @buffered_messages = []
end

Instance Attribute Details

#buffered_messages (readonly, private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 38

attr_reader :buffered_messages

#connection (readonly, private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 37

attr_reader :connection

#processing?Boolean (readonly)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 27

def processing?
  @processing
end

Instance Method Details

#append(message)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 15

def append(message)
  if valid? message
    if processing?
      receive message
    else
      buffer message
    end
  else
    connection.logger.error "Couldn't handle non-string message: #{message.class}"
  end
end

#buffer(message) (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 48

def buffer(message)
  buffered_messages << message
end

#process!

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 31

def process!
  @processing = true
  receive_buffered_messages
end

#receive(message) (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 44

def receive(message)
  connection.receive message
end

#receive_buffered_messages (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 52

def receive_buffered_messages
  receive buffered_messages.shift until buffered_messages.empty?
end

#valid?(message) ⇒ Boolean (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 40

def valid?(message)
  message.is_a?(String)
end