Async::WebSocketSourceAsyncWebSocketClient

class Client

This is a basic synchronous websocket client:

Nested

Definitions

def self.open(endpoint, **options, &block)

Implementation

def self.open(endpoint, **options, &block)
	client = self.new(HTTP::Client.new(endpoint, **options), mask: true)
	
	return client unless block_given?
	
	begin
		yield client
	ensure
		client.close
	end
end

def self.connect(endpoint, *arguments, **options, &block)

Implementation

def self.connect(endpoint, *arguments, **options, &block)
	Sync do
		client = self.open(endpoint, *arguments)
		connection = client.connect(endpoint.authority, endpoint.path, **options)
		
		return ClientCloseDecorator.new(client, connection) unless block_given?
		
		begin
			yield connection
			
		ensure
			connection&.close
			client&.close
		end
	end
end