Sha256: b677e21487e852a3241ef7b2601f85dae39bb0be0f46c00d6b263cb0b5496cfb

Contents?: true

Size: 709 Bytes

Versions: 2

Compression:

Stored size: 709 Bytes

Contents

require 'aggro/nanomsg_transport/request'

module Aggro
  module NanomsgTransport
    # Public: Client for making requests against a nanomsg server.
    class Client
      def initialize(endpoint)
        ObjectSpace.define_finalizer self, method(:close_socket)

        @endpoint = endpoint
      end

      def post(message)
        request_socket.send_msg message

        request_socket.recv_msg
      end

      def close_socket
        request_socket.terminate if @open
        @request_socket = nil
        @open = false
      end

      private

      def request_socket
        @request_socket ||= begin
          @open = true
          Request.new(@endpoint)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aggro-0.0.3 lib/aggro/nanomsg_transport/client.rb
aggro-0.0.2 lib/aggro/nanomsg_transport/client.rb