Class: ActionCable::Connection::MessageBuffer

Inherits:
Object
  • Object
show all
Defined in:
actioncable/lib/action_cable/connection/message_buffer.rb

Overview

Позволяет нам буферизовать сообщения, полученные из WebSocket, до того, как Connection полностью инициализировано и готово к их получению.

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ MessageBuffer

Returns a new instance of MessageBuffer.


5
6
7
8
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 5

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

Instance Method Details

#append(message) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 10

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


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

def process!
  @processing = true
  receive_buffered_messages
end

#processing?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 22

def processing?
  @processing
end