Class: WsClient::AsyncClient

Inherits:
Client
  • Object
show all
Defined in:
lib/ws_client.rb

Constant Summary

Constants inherited from Client

Client::FRAME_SIZE, Client::MS_2

Instance Attribute Summary

Attributes inherited from Client

#connect_options, #message_queue, #url

Instance Method Summary collapse

Methods inherited from Client

#closed?, #connect, #initialize, #open?, #reconnect, #send_data_and_wait

Constructor Details

This class inherits a constructor from WsClient::Client

Instance Method Details

#closeObject



206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/ws_client.rb', line 206

def close
  return if @closed

  write_data nil, :type => :close if !@pipe_broken
  emit :close
ensure
  @closed = true
  @socket.close if @socket
  @tcp_socket.close if @tcp_socket
  @socket = nil
  @tcp_socket = nil
  Thread.kill @thread if @thread
end

#pollObject



225
226
227
228
229
230
231
232
233
234
235
# File 'lib/ws_client.rb', line 225

def poll
  return Thread.new(@socket) do |socket|
    while !@closed do
      pull_next_message_off_of_socket(socket)

      message_queue.length.times do
        emit :message, message_queue.pop
      end
    end
  end
end

#send_data(data, opt = {:type => :text}) ⇒ Object



220
221
222
223
# File 'lib/ws_client.rb', line 220

def send_data(data, opt={:type => :text})
  @thread ||= poll # utilize the polling interface, could probably be split into another class
  write_data(data, opt)
end