Class: OpenAI::WebSocket::AsyncWebSocketTransport::Socket Private

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/helpers/websocket/async_websocket_transport.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(connection, url:, error_factory:) ⇒ Socket

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Socket.



163
164
165
166
167
168
# File 'lib/openai/helpers/websocket/async_websocket_transport.rb', line 163

def initialize(connection, url:, error_factory:)
  @connection = connection
  @url = url
  @error_factory = error_factory
  @aborted = false
end

Instance Method Details

#abortObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



193
194
195
196
197
198
199
200
201
# File 'lib/openai/helpers/websocket/async_websocket_transport.rb', line 193

def abort
  framer = @connection.framer
  framer.extend(AbortableFramer)
  framer.abort
  @aborted = true
rescue StandardError => e
  error = @error_factory.call(url: @url, cause: e)
  raise error, cause: error.cause
end

#aborted?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



204
# File 'lib/openai/helpers/websocket/async_websocket_transport.rb', line 204

def aborted? = @aborted

#close(code: 1000, reason: "") ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



185
186
187
188
189
190
# File 'lib/openai/helpers/websocket/async_websocket_transport.rb', line 185

def close(code: 1000, reason: "")
  @connection.close(code, reason)
rescue StandardError => e
  error = @error_factory.call(url: @url, cause: e)
  raise error, cause: error.cause
end

#closed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



206
# File 'lib/openai/helpers/websocket/async_websocket_transport.rb', line 206

def closed? = @aborted || @connection.closed?

#readObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



170
171
172
173
174
175
# File 'lib/openai/helpers/websocket/async_websocket_transport.rb', line 170

def read
  @connection.read
rescue StandardError => e
  error = @error_factory.call(url: @url, cause: e)
  raise error, cause: error.cause
end

#write(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



177
178
179
180
181
182
183
# File 'lib/openai/helpers/websocket/async_websocket_transport.rb', line 177

def write(message)
  @connection.write(message)
  @connection.flush
rescue StandardError => e
  error = @error_factory.call(url: @url, cause: e)
  raise error, cause: error.cause
end