Class: ActionCable::Server::Socket::MessageBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/action_cable/server/socket/message_buffer.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ MessageBuffer

:nodoc:



8
9
10
11
# File 'lib/action_cable/server/socket/message_buffer.rb', line 8

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

Instance Method Details

#append(message) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/action_cable/server/socket/message_buffer.rb', line 13

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

#process!Object



29
30
31
32
# File 'lib/action_cable/server/socket/message_buffer.rb', line 29

def process!
  @processing = true
  receive_buffered_messages
end

#processing?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/action_cable/server/socket/message_buffer.rb', line 25

def processing?
  @processing
end